-->
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.  [ 2 posts ] 
Author Message
 Post subject: Custom SQL for collection loading - initialize problem
PostPosted: Thu May 11, 2006 8:06 am 
Newbie

Joined: Tue Dec 13, 2005 11:19 am
Posts: 7
Location: Lisboa, Portugal
Hello,
I have two collection in one class for which I am using custom SQL for loading.
There is no exception thrown and in fact hibernate.loader log shows that the records are properly identified and hydrated.
-> Problem is - the collection ends up empty!
Hibernate is configured with lazy initialization=true, but the collections are being specifically initialized in this example.
The property to initialize is a PersistentSet and as you can see, before and after the query execution this PersistentSet shows size=0.
Before:
Code:
nestedPropertyValue= PersistentSet  (id=49)
   cachedSize= -1
   directlyAccessible= false
   dirty= false
   initialized= false
   initializing= false
   key= Long  (id=110)
   operationQueue= null
   owner= OperationDocumentSituation  (id=39)
   role= "com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds"
   session= SessionImpl  (id=60)
   set= null
   storedSnapshot= null
   tempList= null


And after:
Code:
nestedPropertyValue= PersistentSet  (id=55)
   cachedSize= -1
   directlyAccessible= false
   dirty= false
   initialized= true
   initializing= false
   key= Long  (id=111)
   operationQueue= null
   owner= OperationDocumentSituation  (id=39)
   role= "com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds"
   session= SessionImpl  (id=52)
   set= HashSet  (id=122)
      map= HashMap  (id=134)
         entrySet= null
         keySet= HashMap$KeySet  (id=136)
         loadFactor= 0.75
         modCount= 0
         size= 0
         table= HashMap$Entry[16]  (id=138)
         threshold= 12
         values= null
   storedSnapshot= HashMap  (id=127)
   tempList= null


Because the log sais total objects hydrated: 4 I was actually expecting the final size to be 4 and not zero.
Am I wrong?

Any help will be most wellcome.

Hibernate version: 3.1

Mapping documents:
This is the mapping in question: OperationDocumentSituation and the two collections operationDocumentNeeds, and interventionDocumentNeeds
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="com.audaxys.bf.operation.dom.OperationDocumentSituation" table="docsituation" proxy="com.audaxys.bf.operation.dom.OperationDocumentSituation">
        <id name="gid" type="long">
            <column name="gid" />
            <generator class="com.audaxys.fw.dom.id.AppGidGenerator" />
        </id>
        <many-to-one name="operation" class="com.audaxys.bf.operation.dom.Operation">
           <column name="owner_gid" not-null="true" />
        </many-to-one>
        <property name="stateDate" type="date">
            <column name="statedate" not-null="true" />
        </property>
        <many-to-one name="automatonState" class="com.audaxys.be.automaton.dom.AutomatonState">
            <column name="automst_code"/>
        </many-to-one>
       
        <set name="operationDocumentNeeds" inverse="true">
           <key column="sid"/>
           <one-to-many class="com.audaxys.bf.operation.dom.OperationDocumentNeed" />
         <loader query-ref="com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeedsQuery"/>           
        </set>
         
        <set name="interventionDocumentNeeds" inverse="true">
            <key column="sid"/>
            <one-to-many class="com.audaxys.bf.operation.dom.InterventionDocumentNeed" />
            <loader query-ref="com.audaxys.bf.operation.dom.OperationDocumentSituation.interventionDocumentNeedsQuery"/>
        </set>

        <sql-query name="operationDocumentNeedsQuery">
           <load-collection lock-mode="read" alias="dn" role="com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds"/>
               select {dn.*}
               from docneed dn
               join docsituation ds on dn.needing_gid = ds.owner_gid
               where ds.gid = :gid
      </sql-query>

        <sql-query name="interventionDocumentNeedsQuery">
           <load-collection lock-mode="read" alias="dn" role="com.audaxys.bf.operation.dom.OperationDocumentSituation.interventionDocumentNeeds"/>
               select {dn.*}
               from docneed dn
               join intervention interv on interv.gid=dn.needing_gid
               join docsituation ds on ds.owner_gid=interv.operation_gid
               where ds.gid= :gid
      </sql-query>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
        Criteria criteria =  buildCriteria(query);
        if(maxResults > 0)
            criteria.setMaxResults(maxResults);
       
        return initializeNestedPathsOfListResults(criteria.list(), nestedPathsToInitialize);
        .............................................

        getHibernateTemplate().initialize(nestedPropertyValue);


Full stack trace of any exception that occurs:

Name and version of the database you are using: IBM Informix 9.40 for AIX

The generated SQL (show_sql=true):
SQL generated to retrieve the main table (DocumentSituation)
Code:
    select
        first 1 this_.gid as gid185_0_,
        this_.owner_gid as owner2_185_0_,
        this_.statedate as statedate185_0_,
        this_.automst_code as automst4_185_0_
    from
        docsituation this_
    where
        this_.owner_gid=?


After retrieving DocumentSituation, execute getHibernateTemplate().initialize(nestedPropertyValue); for each collection.
This is the SQL generated to retrieve the first collection:
Code:
OperationDocumentNeeds:
    select
        dn.sid as sid0__,
        dn.sid as sid177_0_,
        dn.doctype_gid as doctype2_177_0_,
        dn.needing_gid as needing3_177_0_     
    from
        docneed dn     
    join
        docsituation ds
            on dn.needing_gid = ds.owner_gid     
    where
        ds.gid = ?

Debug level Hibernate log excerpt:
Here is the full debug output:
Code:
2006-05-11 12:48:07,017 DEBUG [org.hibernate.SQL] - <
    select
        first 1 this_.gid as gid185_0_,
        this_.owner_gid as owner2_185_0_,
        this_.statedate as statedate185_0_,
        this_.automst_code as automst4_185_0_
    from
        docsituation this_
    where
        this_.owner_gid=?>
2006-05-11 12:48:07,017 DEBUG [org.hibernate.loader.Loader] - <processing result set>
2006-05-11 12:48:07,017 DEBUG [org.hibernate.loader.Loader] - <result set row: 0>
2006-05-11 12:48:07,017 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[com.audaxys.bf.operation.dom.OperationDocumentSituation#1746861]>
2006-05-11 12:48:07,017 DEBUG [org.hibernate.loader.Loader] - <Initializing object from ResultSet: [com.audaxys.bf.operation.dom.OperationDocumentSituation#1746861]>
2006-05-11 12:48:07,017 DEBUG [org.hibernate.loader.Loader] - <done processing result set (1 rows)>
2006-05-11 12:48:07,033 DEBUG [org.hibernate.loader.Loader] - <total objects hydrated: 1>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <Nested paths to initialize = [Ljava.lang.String;@4928ae[{operationDocumentNeeds,interventionDocumentNeeds}]>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <Nested paths to initialize = [Ljava.lang.String;@4928ae[{operationDocumentNeeds,interventionDocumentNeeds}]>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <initialize nested path of object [com.audaxys.bf.operation.dom.OperationDocumentSituation] with nested path [operationDocumentNeeds]...>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <object provided already initialized !!!>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <initialize nested path [operationDocumentNeeds] from entity [com.audaxys.bf.operation.dom.OperationDocumentSituation]>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <get value of nestedProperty [operationDocumentNeeds]...>
2006-05-11 12:48:25,723 DEBUG [com.audaxys.fw.dal.support.ReadOnlySunsetDaoImpl] - <initialize nested value of nestedProperty [operationDocumentNeeds]...>
2006-05-11 12:48:38,338 DEBUG [org.hibernate.SQL] - <
    select
        dn.sid as sid0__,
        dn.sid as sid177_0_,
        dn.doctype_gid as doctype2_177_0_,
        dn.needing_gid as needing3_177_0_
    from
        docneed dn
    join
        docsituation ds
            on dn.needing_gid = ds.owner_gid
    where
        ds.gid = ?>
2006-05-11 12:48:38,338 DEBUG [org.hibernate.loader.Loader] - <bindNamedParameters() 1746861 -> gid [1]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result set contains (possibly empty) collection: [com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds#1746861]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <processing result set>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result set row: 0>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[com.audaxys.bf.operation.dom.OperationDocumentNeed#8875]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <Initializing object from ResultSet: [com.audaxys.bf.operation.dom.OperationDocumentNeed#8875]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <found row of collection: [com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds#8875]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result set row: 1>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[com.audaxys.bf.operation.dom.OperationDocumentNeed#8876]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <Initializing object from ResultSet: [com.audaxys.bf.operation.dom.OperationDocumentNeed#8876]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <found row of collection: [com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds#8876]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result set row: 2>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[com.audaxys.bf.operation.dom.OperationDocumentNeed#8878]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <Initializing object from ResultSet: [com.audaxys.bf.operation.dom.OperationDocumentNeed#8878]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <found row of collection: [com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds#8878]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result set row: 3>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <result row: EntityKey[com.audaxys.bf.operation.dom.OperationDocumentNeed#9047]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <Initializing object from ResultSet: [com.audaxys.bf.operation.dom.OperationDocumentNeed#9047]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <found row of collection: [com.audaxys.bf.operation.dom.OperationDocumentSituation.operationDocumentNeeds#9047]>
2006-05-11 12:48:38,417 DEBUG [org.hibernate.loader.Loader] - <done processing result set (4 rows)>
2006-05-11 12:48:38,432 DEBUG [org.hibernate.loader.Loader] - <total objects hydrated: 4>


Thank you for your support.

_________________
Carlos


Top
 Profile  
 
 Post subject: Re: Custom SQL for collection loading - initialize problem
PostPosted: Thu Jul 20, 2006 10:44 am 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
Did you figure this one out? I am having the same problem and I am at my wits end

_________________
Thanks
Sameet


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.