-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate bug using criteria queries with annotation
PostPosted: Sat Dec 09, 2006 6:59 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hibernate version:
3.2.1 and 3.2

I have a 1:n to 1:n relation, ie. Forest has many Trees has many Leafs.

I try to select all Trees having a leaf which name is test.


Code:
session.createCriteria(Tree.class).createCriteria("leafs").add(Restrictions.eq("name", "test")).list();


If I use XML mapping, I receive a proper query:

Code:
select this_.id as id1_1_, leaf1_.id as id0_0_, leaf1_.name as name0_0_, leaf1_.tree_id as tree3_0_0_
  from tree this_ inner join leaf leaf1_ on this_.id=leaf1_.tree_id where leaf1_.name=?


but if I use annotation mapping, I get a very ugly join returning not even the correct values:
Code:
select this_.id as id2_3_, this_.forest_id as forest2_2_3_, leaf1_.id as id0_0_, leaf1_.tree_id as tree3_0_0_,
leaf1_.name as name0_0_, tree4_.id as id2_1_, tree4_.forest_id as forest2_2_1_, forest5_.id as id1_2_
from Tree
this_ inner join Leaf leaf1_ on this_.id=leaf1_.tree_id
  left outer join Tree tree4_ on leaf1_.tree_id=tree4_.id
  left outer join Forest forest5_ on tree4_.forest_id=forest5_.id where leaf1_.name=?


I found this topic in the forum but it was not stated as bug. Before filing a bug I would like to get some feedback. An example project with all mappings and classes can be downloaded here.
http://www.laliluna.de/HibernateTest.zip

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.