【发布时间】:2010-09-14 11:25:22
【问题描述】:
您是否有 Hibernate 实体的通用基类,即具有 id、版本和其他通用属性的 MappedSuperclass?有什么缺点吗?
例子:
@MappedSuperclass()
public class BaseEntity {
private Long id;
private Long version;
...
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
@Version
public Long getVersion() {return version;}
...
// Common properties
@Temporal(TemporalType.TIMESTAMP)
public Date creationDate() {return creationDate;}
...
}
@Entity
public class Customer extends BaseEntity {
private String customerName;
...
}
【问题讨论】:
标签: java hibernate entities base-class