-->
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: should I use .createCriteria or .load for...?
PostPosted: Thu Mar 10, 2005 5:36 pm 
Newbie

Joined: Mon Feb 28, 2005 5:46 pm
Posts: 7
Let's say I have a hypothetical class named myClass that is mapped many-to-many to another class, otherClass. Loading a list of myClass objects from the database thus returns a corresponding Set of otherClass objects for each myClass entity in the list. Which method of loading a single myClass object and it's corresponding otherClass Set is preferrable?

Code:
myClass myObj = (myClass) ses.load(myClass.class, idValue);
List otherClassList = new ArrayList();
otherClassList.addAll( myObj.getOtherClassObjects() );


Code:
Criteria resultCriteria = ses.createCriteria( myClass.class )
            .add( Expression.eq( "myClassId", idValue ) );
ArrayList myClassList = new ArrayList();
myClassList.addAll( resultCriteria.list() );

List otherClassList = new ArrayList();
otherClassList.add( (otherClass)myClassList.get(0) );


The first method obviously seems a lot more clear-cut, however is there a logical difference between the two methods that I'm not getting? In this situation I only need to retrieve data and not save or update anything.


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.