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

时间:2016-06-13 13:00:47

标签: java hibernate criteria hibernate-criteria many-to-one

我有一个带标准的Hibernate查询。

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

这是因为hibernate在其他表上创建和Left连接。 我能算出怎么做。

我发现这2个链接无法解决我的问题:

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

What is the difference between DELETE_ORPHAN and DELETE?

1 个答案:

答案 0 :(得分:1)

如果你有这样的映射:

//Parent
public class A {
    ...
}

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

请尝试这样的事情:

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