-->
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: Criteria Query- double selects, overwrites object graph
PostPosted: Tue Jun 29, 2004 3:32 pm 
Newbie

Joined: Wed Jun 23, 2004 4:35 pm
Posts: 13
I have an object mapped like this;

Code:
    <class name="Recip"
...   
     >
      
        <cache usage="read-only" />

        <id
            name="id"
            column="rid"
            type="java.lang.Integer">
         
            <generator class="assigned"/>
        </id>

        <property
... 
       />

   <one-to-one
         name="serSet"
         class="SerSet"
         outer-join="false"/>
         
   <set name="dnaSet">
      <key column="rid"/>
      <one-to-many class="AntHist"/>
   </set>

    </class>


The following query works fine;

Code:
Criteria criteria = session.createCriteria(Recip.class)
                          .add(Expression.eq("id", new Integer(123456)));
criteria.createCriteria("serSet")
            .add(Expression.eq("phenSeqNumber", new Integer(1)));


But if I add this;

Code:
criteria.createCriteria("dnaSet")
            .add(Expression.like("typMeth", "DNA"));


Then hibernate performs two selects instead of one. Worst of all, the sql from the first is correct and maps to the object graph correctly but the second select gets bad results and overwrites the object graph.

How do I get it to stop?


Top
 Profile  
 
 Post subject: Don't extend java.util.Set?
PostPosted: Tue Jun 29, 2004 5:56 pm 
Newbie

Joined: Wed Jun 23, 2004 4:35 pm
Posts: 13
One thing I left out that I now realize is critical;

The class I use for dnaSet is actually an extension of HashSet. Although the property is passed in as a Set, I transform the Set into a DnaSet before storage.

Since Hibernate replaces Collection objects with its own versions of Collections, the cache can no longer recognize a Collection it has already loaded. So it attempts to lazily initialize the collection but now is wrong-footed.

The solution seems to be to not extend HashSet and place the needed functionality in another object. Which would seem to be a better plan anyway since the goal was to "flatten out" the data in the first place.


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.