Hibernate:实体映射中的重复列|相同类型的两个嵌入式类
Hibernate在创建表时引发异常,因为嵌入的属性映射到同一列 班级距离在班级路线中嵌入两次,如下所示:Hibernate:实体映射中的重复列|相同类型的两个嵌入式类,hibernate,jpa,hibernate-mapping,Hibernate,Jpa,Hibernate Mapping,Hibernate在创建表时引发异常,因为嵌入的属性映射到同一列 班级距离在班级路线中嵌入两次,如下所示: @Embeddable public class Distance implements Serializable{ private static final long serialVersionUID = -8466495790824502626L; @Column(nullable = false) protected Integer distInSec;
@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的DistInse映射到表路由中的同一列“DistInse”。因此,在实体的映射中抛出错误org.hibernate.MappingException:Repeated列
如果可能,我希望更改配置,使其始终生成名为currentDetour_Distance和currentDist_Distance的列。有人知道怎么做吗
提前感谢用于自定义列名。用于自定义列名。使用DefaultComponentSafeNamingStrategy作为命名策略解决了问题使用DefaultComponentSafeNamingStrategy作为命名策略解决了问题这是可行的,但不是默认配置。无论如何谢谢你!这可以工作,但不是默认配置。无论如何谢谢你!