java - org.hibernate.mapping.JoinedSubclass cannot be cast to org.hibernate.mapping.RootClass, two @Id - Stack Overflow

I am migrating xml configuration to annotations.I have a class:@Entity@Table(name = "INSTRUMENT

I am migrating xml configuration to annotations.

I have a class:

@Entity
@Table(name = "INSTRUMENT_OFFERINGS")
@Inheritance(strategy = InheritanceType.JOINED)
public class InstrumentOffering extends HibernatePersistentObject
        implements Serializable, Comparable<InstrumentOffering>
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "instrument_offerings_sequence")
    @SequenceGenerator(name = "instrument_offerings_sequence", sequenceName = "instrument_offerings_sequence")
    @Column(name = "INSTRUMENT_OFFERINGS_ID")
    private Integer instrumentOfferingId;

and second which is extending previous:

@Entity
@Table(name = "INSTRUMENT_OFFERINGS_HISTORY")
@PrimaryKeyJoinColumn(name = "INSTR_OFFERINGS_ID")
public class InstrumentOfferingHistory extends InstrumentOffering {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "instrument_history_seq")
    @SequenceGenerator(name = "instrument_history_seq", sequenceName = "instrument_history_seq")
    @Column(name = "INSTRUMENT_HISTORY_ID")
    private Integer instrumentHistoryId;

I know that it's failing because I have two @Ids. It's unbelivable that this construction was working in xml configuration but how should I handle it now?

InstrumentOfferingsId is different than InstrumentOfferingsHistoryId and can't be shared. INSTRUMENT_OFFERINGS has Id and INSTRUMENT_OFFERINGS_HISTORY should has it's own Id. Plus INSTRUMENT_OFFERINGS_HISTORY can have one INSTRUMENT_HISTORY_ID but it's @ManyToOne to INSTRUMENT_OFFERINGS.

I should create third class without @Id which both classes will extend and both will have their own @Id? Is there different way?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745611759a4635986.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信