最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论