DOM4J createQuery 不急切地获取

发布于 2024-11-13 15:42:33 字数 1839 浏览 4 评论 0原文

我有一个实体,其中包含与第二个实体的一对多关系,具有急切的获取功能。第二个实体有两个 OneToOne 关系,也具有与第三个和第四个类的急切获取关系。 OneToOne 关系是单向的。

我从 DOM4J 会话调用 createQuery() 并发送“来自实体”作为 HQL。在返回中,我得到第二个实体,但它仅包含第三个和第四个实体的 ID,而不是完整的内容。在我看来,第三个和第四个实体似乎并没有被急切地获取。我无法准确地重现代码,但这是最相关的部分。

@Entity
public class Event extends EventParent {
   @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @JoinColumn(name="eventId")
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Set<Pair> pairs=new HashSet<MarPair>();
}

@Entity
public class Pair extends PairParent {
   @OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Info info;

   @OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Results results;
}

@Entity
public class Info {
   private String name;
   private Date time;
}


@Entity
public class Results {
   private String name;
   private Date time;
}

最后,这是我用于查询的代码:

public void retrieve() {
   String hqlQry = "from Event";
   Session session = dom4JSessionFactory.getCurrentSession();
   Session dom4jSession = session.getSession(EntityMode.DOM4J);
   List results = dom4jSession.createQUery(hqlQuery).list();
}

正如我所提到的,从这个查询中,我返回了 info 和 results 值的整数,这是 info 和 results 表的关键,而不是从中检索的实际数据信息和结果表。

相关信息:

  • Spring 2.5.4
  • Hibernate 3.2.6
  • Hibernate Annotations 3.3.1.GA
  • dom4JSessionFactory 的类型为 org.springframework.orm.hibernate3.LocalSessionFactoryBean
  • 实体“Event”实际上是类层次结构中的第七个类(不要知道这是否重要)

我确实遗漏了很多信息,希望没有必要。如果您还有其他需要冒险猜测它不起作用的原因,请告诉我。

I have an entity which contains a OneToMany relationship, with eager fetching, with a second entity. This second entity has two OneToOne relationships, with eager fetching also, to a third and fourth class. The OneToOne relationships are unidirectional.

I am calling createQuery() from a DOM4J session sending in "from entity" as the HQL. In the return I get the second entity but it contains only the IDs of the third and fourth entities instead of the complete contents. To me it looks like those third and fourth entities are not being eagerly fetched. I can't reproduce the code exactly but here is the most relevant parts.

@Entity
public class Event extends EventParent {
   @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @JoinColumn(name="eventId")
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Set<Pair> pairs=new HashSet<MarPair>();
}

@Entity
public class Pair extends PairParent {
   @OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Info info;

   @OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
   @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Results results;
}

@Entity
public class Info {
   private String name;
   private Date time;
}


@Entity
public class Results {
   private String name;
   private Date time;
}

Finally here is the code I am using for the query:

public void retrieve() {
   String hqlQry = "from Event";
   Session session = dom4JSessionFactory.getCurrentSession();
   Session dom4jSession = session.getSession(EntityMode.DOM4J);
   List results = dom4jSession.createQUery(hqlQuery).list();
}

As I mentioned, from this query I am getting back an integer for the value of info and results which is the key to the info and results table instead of the actual data being retrieved from the info and results table.

Relevant Information:

  • Spring 2.5.4
  • Hibernate 3.2.6
  • Hibernate Annotations 3.3.1.GA
  • dom4JSessionFactory is of type org.springframework.orm.hibernate3.LocalSessionFactoryBean
  • The entity "Event" is actually the 7th class down in a class hierarchy (don't know if this matters or not)

I did leave out a lot of information hoping that it was not necessary. If there is something else you would need to venture a guess as to why it isn't working, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡離愁欲言轉身 2024-11-20 15:42:33

事实证明这是我们正在使用的 Hibernate 版本的一个错误。我要做的就是在 Hibernate 生成 HBM 文件后将 embed-xml 更改为 true。这是使用“替换”ant 函数完成的。

Turns out this is a bug with the Hibernate version we are using. What I had to do was to change embed-xml to true after Hibernate generated the HBM files. This was done using the "replace" ant function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文