-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL & outer joins
PostPosted: Tue Aug 16, 2005 7:18 pm 
Newbie

Joined: Tue Jul 19, 2005 8:58 am
Posts: 6
I have been trying to understand the paragraph on pp 261 in the book that states:

Quote:
HQL always ignores the mapping document eager fetch (outer join) setting


This is confusing, as when I try it, it seems like the complete opposite. With a really simple mapping file:

Code:
   <class name="Category" table="categories">
      <id name="id" type="long">
         <generator class="native" />
      </id>
      <property name="name" type="string" />
   </class>

   <class name="Item" table="items">
      <id name="id" type="long">
         <generator class="native" />
      </id>
      <property name="name" type="string" />
      <many-to-one name="category" column="category_id"
         class="Category" outer-join="true"/>
   </class>

   <class name="Bid" table="bids">
      <id name="id" type="long">
         <generator class="native" />
      </id>
      <property name="name" type="string" />
      <many-to-one name="item" column="item_id"
         class="Item"  outer-join="true"/>
   </class>


I get an exception if I try:

Code:
        Session session = sessionFactory.openSession();
        Bid bid = (Bid) session.createCriteria(Bid.class).uniqueResult();
        System.out.println(bid.getName());
        System.out.println(bid.getItem().getName());
        session.close();
        System.out.println(bid.getItem().getCategory().getName());


or if I replace with

Code:
        Bid bid = (Bid) session.get(Bid.class,new Long(1));


If, however, I use an HQL query
Code:
Bid bid = (Bid) session.createQuery("from Bid").uniqueResult();


everything works fine. Removing the second System.out.println results in the org.hibernate.LazyInitializationException, but not if I remove the first. I am totally confused.

Jonas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:21 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are using Hibernate 3.x, the book talks about Hibernate 2.x.


Top
 Profile  
 
 Post subject: 3.0 more different than I thought
PostPosted: Sat Aug 27, 2005 7:47 am 
Newbie

Joined: Tue Jul 19, 2005 8:58 am
Posts: 6
Thanks. I thought I understood the changes made in Hibernate 3 wrt Lazy loading. I'll just stick to 2.1 for now.

Jonas


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

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.