我正在尝试创建一种使用AbstractEntity来建模未来aplications的方法--我现在的问题是Postgres的序列类型
在我的抽象类中,我现在不知道如何生成每个实体类的一个序列
有可能吗?
文摘
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Abstract {
@Id
@GeneratedValue(generator="seq_Broker",strategy=GenerationType.SEQUENCE)
@SequenceGenerator(name="seq_Broker",sequenceName="seq_Broker")
private Long id;
}EntityModel
@Entity
@Table(name = "tb_EntityModel")
public class EntityModel extends Abstract{
private String value;
private String value2;
public EntityModel(String value, String value2) {
this.value = value;
this.value2 = value2;
}
}发布于 2015-07-30 16:11:32
对于任何继承类型,@Entity超类都是不可能的,因为主表(用于Abstract的表)总是包含使用的is -显然只能使用一个序列,否则就会出现唯一性问题。
但是您可以为@MappedSuperclass为Abstract定义
@MappedSuperclass
public abstract class Abstract {
public static final String SEQUENCE_GENERATOR = "seq";
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQUENCE_GENERATOR)
private Long id;
}
@Entity
@Table(name = "tb_EntityModel")
@SequenceGenerator(name = Abstract.SEQUENCE_GENERATOR, sequenceName = "tb_entity_sequence")
public class EntityModel extends Abstract {
...
}https://stackoverflow.com/questions/31726346
复制相似问题