休眠:如何覆盖从超映射类的属性 [英] Hibernate : How override an attribute from mapped super class
本文介绍了休眠:如何覆盖从超映射类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通用实体,超类:
@MappedSuperclass
public abstract class GenericEntity {
private Integer id;
public Integer getId() {return id;}
public void setId(Integer id) {this.id = id;}
}
该POJO:
@Entity
@Table(name = "POJO_ONE")
@SequenceGenerator(name = "HB_SEQ_POJO_ONE", sequenceName = "SEQ_POJO_ONE", allocationSize = 1)
public class PojoOne extends GenericEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HB_SEQ_POJO_ONE")
@Column(name = "ID")
@AttributeOverride(name = "id", column = @Column(name = "ID"))
private Integer id;
@Override
public Integer getId() {return id;}
}
我尝试使用放入系统注释:@AttributeOverride,@Id,...但它不工作。你可以帮我吗?
我想重写属性ID指定另一个列名和POJO /表中的顺序。
什么是做到这一点的最好办法?
I try to use thoses annotations : @AttributeOverride, @Id, ... but It doesn't work. Can you help me? I want to override the attribute "id" to specify another column name and a sequence by pojo/table. What is the best way to do that?
推荐答案
试试这个,而不是
@MappedSuperclass
public abstract class GenericEntity {
private Integer id;
...
public Integer getId() {return id;}
public void setId(Integer id) {this.id = id;}
}
@Entity
@Table(name = "POJO_ONE")
@SequenceGenerator(name = "HB_SEQ_POJO_ONE", sequenceName = "SEQ_POJO_ONE", allocationSize = 1)
@AttributeOverride(name = "id", column = @Column(name = "ID"))
public class PojoOne extends GenericEntity {
// we should not define id here again
...
@Override
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HB_SEQ_POJO_ONE")
public Integer getId() {return id;}
}
这篇关于休眠:如何覆盖从超映射类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文