-->
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: setFetchMode(JOIN): do implicit association paths exist?
PostPosted: Fri Aug 21, 2009 11:38 am 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hi

I'm confused with setFetchMode.

I have a 3 tables:
BSCSContractAll n <---> 1 BSCSCustomerAll n <---> 1 BSCSBillcycles

When I write a query:
Code:
final BSCSContractAll bscsContractAll =
   (BSCSContractAll)
   PersistenceUtil.getHibernateSession(em)
   .createCriteria(BSCSContractAll.class)
   .setFetchMode("bscsCustomerAll", FetchMode.JOIN)
   .setFetchMode("bscsCustomerAll.bscsBillcycles", FetchMode.JOIN)
   .add(Restrictions.idEq(iCoId))
   .uniqueResult();


... everything works perfectly, I mean there is the only one SQL against all 3 tables joined (by Hibernate) respectively.

But when I use only one single association path "bscsCustomerAll.bscsBillcycles":
Code:
final BSCSContractAll bscsContractAll =
   (BSCSContractAll)
   PersistenceUtil.getHibernateSession(em)
   .createCriteria(BSCSContractAll.class)
   .setFetchMode("bscsCustomerAll.bscsBillcycles", FetchMode.JOIN)
   .add(Restrictions.idEq(iCoId))
   .uniqueResult();


... then Hibernate generates a SQL query only against one (first) table: BSCSContractAll :(

So my question is:
Is specifying only one association path "bscsCustomerAll.bscsBillcycles" not enough to instruct Hibernate that I want to join *all 3* in a one single SQL?


btw:
Looking on Java file in hibernate-3.3.1 distribution I found both approaches - two pieces of Hibernate test code:

Single association path:
Code:
      list = s.createCriteria(Foo.class)
         .setFetchMode("component.importantDates", FetchMode.EAGER)
         .list();


Both association paths:
Code:
      parents = s.createCriteria(Parent.class)
         .setFetchMode("moreChildren", FetchMode.JOIN)
         .setFetchMode("moreChildren.friends", FetchMode.JOIN)
         .addOrder( Order.desc("name") )
         .list();


I'm confused...

Take care and have a nice weekend!
Adam Wozniak


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.