Grails2.4中JPA@MappedSuperclass的实现
我找到了解决办法,但解决不了问题。在JPA中,我们可以这样做:Grails2.4中JPA@MappedSuperclass的实现,jpa,gorm,grails-2.4,Jpa,Gorm,Grails 2.4,我找到了解决办法,但解决不了问题。在JPA中,我们可以这样做: @MappedSuperclass public class BasicEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(updatable = false) @Temporal(TemporalType.TIMESTAMP) private Date crea
@MappedSuperclass
public class BasicEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date created = new Date();
@Temporal(TemporalType.TIMESTAMP)
private Date modified = new Date();
}
@Entity
public class User extends BasicEntity {
private String username;
private String password;
}
然后,hibernate.hbm2ddl.auto生成一个包含所有继承列的表,这正是我想要的:
user (
id,
created,
modified,
username,
password,
)
在Grails中,我这样做
abstract class BasicEntity {
static mapping = {
tablePerSubclass true
}
Date dateCreated
Date lastUpdated
}
class User extends BasicEntity {
String username
String password
}
它生成了两个没有继承的表
basic_entity (
id,
version,
date_created,
last_updated,
)
user (
id,
username,
password,
)
可能重复的