是否可以在Hibernate中重用已定义的列?
我有大约20个表,每个表至少需要修改和创建,以及其他一些对所有这些列都相同的字段。
我试过这样做:
public class ModifiedCreated {
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Date created;
@Version
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "M-")
private Date modified;
public ModifiedCreated() {
created = new Date();
modified = new Date();
}
@PrePersist
protected void onPersist() {
if (created == null) {
created = new Date();
}
if (modified == null) {
modified = new Date();
}
}
@PreUpdate
protected void onUpdate() {
modified = new Date();
}
public Date getModified() {
return modified;
}
public Date getCreated() {
return created;
}
}
和Route.java
@RooJavaBean
@RooToString
@RooEntity
public class Route extends ModifiedCreated {
private String name;
@ManyToMany(cascade = CascadeType.ALL)
private Set<Note> notes = new HashSet<Note>();
}
是否可以在Hibernate中重用列?
答案 0 :(得分:3)
使用ModifiedCreated
注释为您的@MappedSuperclass
课程添加注释
(这是hibernate的注释。但我不知道spring-roo对此做了什么)