0

In my app I have a meeting object with its properties stored in a meeting table. I have to create a new object, let's say "meetingNEW" having some different properties, but most of them common.

I'm thinking to use the table per concrete class strategy, but I'd like to have separate ids for the two tables and not inherit it from the superclass. Is it possible? I'm only finding examples with a common id.

My idea is: MeetingType -> abstract superclass

Meeting extends MeetingType with Meeting_id as PK (table)

MeetingNEW extends MeetingType with meetingNEW_id as PK (table)

Thanks

SG87
  • 79
  • 12

1 Answers1

0

Why do you use Table per concrete class strategy ? For me it seems like table per subclass strategy like below with meeting_type table with common properties and other tables with specific properties with its own PK id.

 @Entity @Inheritance(strategy = InheritanceType.JOINED)
 public class MeetingType {
      @Id
      @Column("meeting_type_id")  
      public long getId();
 }

 @Entity @PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name = "meeting_id", referencedColumnName = "meeting_type_id") })
 public class Meeting extends MeetingType {
   @Column("meeting_id")  
   public long getMeetingId();
 }

 @Entity @PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name = "meeting_new_id", referencedColumnName = "meeting_type_id") })
 public class MeetingNew extends MeetingType {
   @Column("meeting_new_id")  
   public long getMeetingNewId();
}
Anudeep Gade
  • 1,365
  • 1
  • 9
  • 18
  • because I don't want to create a table for the superclass, I don't need it. I'm doing some test and it seems it's possible to use different PK. – SG87 Aug 18 '15 at 08:59
  • OK i see, IMHO its not a good db design as you are duplicating common properties in sub class tables. But anyway your approach is right with abstract class and subclasses but then your subclasses should have @Id columns to have different id's. – Anudeep Gade Aug 18 '15 at 09:07
  • I know it's not the best approach but the app exists since 5 years and it would be really a mess to change the id name in every place. Also this new table won't be use a lot. I have some common property in the abstract class but they are duplicated in the 2 tables. +1 for answering – SG87 Aug 18 '15 at 09:15