Hibernate - Table per concrete class strategy - separate IDs for each table

322 views Asked by At

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

1

There are 1 answers

3
Anudeep Gade On BEST ANSWER

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();
}