【发布时间】:2011-11-07 18:32:52
【问题描述】:
Hibernate 在创建表时抛出异常,因为嵌入的属性映射到同一列。
类Distance在类路由中嵌入两次,如下所示:
@Embeddable
public class Distance implements Serializable{
private static final long serialVersionUID = -8466495790824502626L;
@Column(nullable = false)
protected Integer distInSec;
public Distance() {
super();
}
}
@Entity
public class Route{
@Column(nullable=false)
protected Distance currentDetour;
@Column(nullable=false)
protected Distance currentDist;
}
当 hibernate 创建表时,它会尝试将 currentDetour 和 currentDist 的 distInSec 映射到表路由中的同一列“distInSec”。因此,错误 org.hibernate.MappingException: Repeated column in mapping for entity: 被抛出。
如果可能,我想更改配置,使其始终生成名称为 currentDetour_distInSec 和 currentDist_distInSec 的列。有人知道怎么做吗?
提前致谢
【问题讨论】:
标签: hibernate jpa hibernate-mapping