我有一个带有 Criteria 的 Hibernate 查询。
我想做的是(仅针对一个查询)告诉 hibernate 忽略现有的 @ManyToOne
注释。
这是因为 hibernate 在其他表上创建并左连接。 我能想到该怎么做。
我发现这两个链接没有解决我的问题:
Hibernate: How to remove an entity to which none refers to anymore in ManyToOne?
最佳答案
如果你有这样的映射:
//Parent
public class A {
...
}
//Child
public class B {
private A parent; //Many to one
...
}
请尝试这样的事情:
Criteria q = ....;
q.setFetchMode("parent", FetchMode.SELECT);
....
关于Java Hibernate暂时忽略带有条件的@ManyToOne注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790538/