-->
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: Problems With Subcriteria and Joins
PostPosted: Wed Mar 05, 2008 5:58 pm 
Newbie

Joined: Wed Mar 05, 2008 5:19 pm
Posts: 1
I'm using eager fetching by setting the mode to join.
The SQL generated executes the correct query.
If I access the contents of the subfleet collection outside the context of a session I get a lazily initialization exception.
If I access the contents inside a session it executes more queries
Why does it still try to evaluate the queries lazily?

Thanks!

Hibernate version:
3.2.5
Mapping documents:

Code:
     <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
       
<hibernate-mapping>

   <class name="Fleet" table="fleet">
   
        <id name="number" column="id">
           <generator class="sequence">
              <param name="sequence">fleet_id_seq</param>
           </generator>
        </id>
       
        <natural-id mutable="true">
           <property name="name" not-null="true"/>
        </natural-id>
       
        <set name="subFleets" table="subfleet" cascade="delete-orphan" inverse="true">
           <key column="fleet" not-null="true" on-delete="cascade"/>
           <one-to-many class="SubFleet"/>
        </set>
     
    </class>


    <class name="SubFleet" table="subfleet">
   
       <id name="number" column="id">
          <generator class="sequence">
             <param name="sequence">subfleet_id_seq</param>
          </generator>
       </id>

       <natural-id mutable="true">
          <property name="name" not-null="true"/>
          <many-to-one name="fleet" not-null="true" class="Fleet" />          
       </natural-id>
              
       <set name="vehicles" table="subfleet_vehicle" cascade="save-update">
          <key column="subfleet_id" not-null="true" />
          <many-to-many class="Vehicle" column="vehicle_id" />
       </set>
       
    </class>
   
   
    <class name="Vehicle" table="vehicle">
       
       <id name="id">
          <generator class="sequence">
             <param name="sequence">vehicle_id_seq</param>
          </generator>
       </id>
              
       <set name="subFleets" table="subfleet_vehicle" inverse="true" cascade="save-update">
          <key column="vehicle_id" not-null="true" />
          <many-to-many class="SubFleet" column="subfleet_id" />
       </set>
    </class>
</hibernate-mapping>



Java Classes
Code:
   
public class Fleet {

   public long number;
   public String name;
   public Set<SubFleet> subFleets;
}

   public class SubFleet {

   public long number;
   public String name;
   public Fleet fleet;
   public Set<Vehicle> vehicles;
}

public class Vehicle  {

   public long id;
   public Set<SubFleet> subFleets;
}


Code between sessionFactory.openSession() and session.close():
Code:
 
Criteria fleetCrit = session.createCriteria(Fleet.class);
      fleetCrit.setFetchMode("subFleets", FetchMode.JOIN);
      
      Criteria subFleetCrit = fleetCrit.createCriteria("subFleets");
      subFleetCrit.setFetchMode("vehicles", FetchMode.JOIN);
      
      List<Fleet> fleetList = fleetCrit.list();



Name and version of the database you are using:
Oracle9i

Error generated ERROR [LazyInitializationException] failed to lazily initialize a collection of role: Fleet.subFleets, no session or session was closed[/b]


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.