【问题标题】:Java Hibernate temporarily Ignore @ManyToOne annotaion with criteriaJava Hibernate 暂时忽略带有条件的 @ManyToOne 注释
【发布时间】:2016-06-13 13:00:47
【问题描述】:

我有一个带有 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?

【问题讨论】:

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


    【解决方案1】:

    如果你有这样的映射:

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

    请尝试以下方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 2018-06-20
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      相关资源
      最近更新 更多