Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate:实体映射中的重复列|相同类型的两个嵌入式类_Hibernate_Jpa_Hibernate Mapping - Fatal编程技术网

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;

Hibernate在创建表时引发异常,因为嵌入的属性映射到同一列

班级距离在班级路线中嵌入两次,如下所示:

@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作为命名策略解决了问题

这是可行的,但不是默认配置。无论如何谢谢你!这可以工作,但不是默认配置。无论如何谢谢你!