Specifying distinct sequence per table in Hibernate on subclasses

前端 未结 5 740
北荒
北荒 2020-12-28 14:47

Is there a way to specify distinct sequences for each table in Hibernate, if the ID is defined on a mapped superclass?

All entities in our application extend a super

5条回答
  •  旧时难觅i
    2020-12-28 15:20

    Have you tried doing it this way ?

    @MappedSuperclass
    public abstract class DataObject implements Serializable {
        @Id 
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idgen")
        @Column(name = "id")
        private int id;
    }
    
    @Entity
    @SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entityaseq")
    @Table(name = "entity_a")
    public class EntityA extends DataObject { 
    
    }
    
    @Entity
    @SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entitybseq")
    @Table(name = "entity_b")
    public class EntityB extends DataObject {
    
    }
    

    I'm sorry I don't have the required environment to test it right now but I'll try it later.

提交回复
热议问题