Hibernate 与查询的OneToOne关系
我目前正在将一段使用JDBC(不是为JPA设计的)的代码迁移到Hibernate,我有两个实体,我想用一对一的关系链接它们。 以下是有助于解释我的问题的类似实体: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
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,但我认为它们太麻烦了,无法提出这个问题。太好了。很高兴我能帮忙