Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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 与查询的OneToOne关系_Hibernate_Spring Data_One To One - Fatal编程技术网

Hibernate 与查询的OneToOne关系

Hibernate 与查询的OneToOne关系,hibernate,spring-data,one-to-one,Hibernate,Spring Data,One To One,我目前正在将一段使用JDBC(不是为JPA设计的)的代码迁移到Hibernate,我有两个实体,我想用一对一的关系链接它们。 以下是有助于解释我的问题的类似实体: Entity A complexKey : String Entity B complexSubKey1: String complexSubKey2: String complexSubKey3: String 对于这个例子,我想在必要时链接实体A和B complexKey=complexSubKey1+:“+compl

我目前正在将一段使用JDBC(不是为JPA设计的)的代码迁移到Hibernate,我有两个实体,我想用一对一的关系链接它们。 以下是有助于解释我的问题的类似实体:

Entity A
 complexKey : String

Entity B
 complexSubKey1: String
 complexSubKey2: String
 complexSubKey3: String
对于这个例子,我想在必要时链接实体A和B

complexKey=complexSubKey1+:“+complexSubKey2+”:”+ complexSubKey3


我真的不知道如何实现这一点。

您应该能够通过使用
JoinColumnOrFormula
注释来实现这一点

public class B{

    @OneToOne
    @JoinColumnsOrFormulas(
           { 
              @JoinColumnOrFormula(
                 formula=@JoinFormula(value="concat(complexSubKey1,':','complexSubKey2',':',complexSubKey3)"
                     , referencedColumnName="complexKey")) 
           })
    @Fetch(FetchMode.JOIN)
    private A a;
}

您是否创建了POJO和映射关系?与查询的关系…您到底想实现什么?我正在开发一个不是为JPA(和关系)设计的遗留代码,我确实有POJO,但我认为它们太麻烦了,无法提出这个问题。太好了。很高兴我能帮忙