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.