Java 暂时休眠 忽略带有条件的@ManyToOne 注释

Java Hibernate temporarily Ignore @ManyToOne annotaion with criteria

我有一个带条件的 Hibernate 查询。

我想做的是(仅针对一个查询)告诉 hibernate 忽略现有的 @ManyToOne 注释。

那是因为 hibernate 在其他表上创建和左连接。 我知道怎么做了。

我发现这 2 个链接没有解决我的问题:

Hibernate: How to remove an entity to which none refers to anymore in ManyToOne?

What is the difference between DELETE_ORPHAN and DELETE?

如果你有这样的映射:

//Parent
public class A {
    ...
}

//Child
public class B {
   private A parent; //Many to one
   ...
}

请尝试这样的操作:

Criteria q = ....;
q.setFetchMode("parent", FetchMode.SELECT);
....