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: why methond throws NotUniqueObjectException ?
PostPosted: Wed Dec 14, 2005 7:02 am 
Newbie

Joined: Fri Dec 24, 2004 4:09 am
Posts: 11
Under some circumstance(not all the time) following methond throws NotUniqueObjectException

Code:
public FooObject getFooObject (Class clazz, long id, Session session) throws HibernateException{
   Criteria criteria = session.createCriteria(clazz);
   criteria.add(Expression.eq(“id”, new Long(id)));
   return (Executor) criteria.uniqueResult();
}


while the following method never throws NotUniqueObjectException

Code:
public FooObject getFooObject(Class clazz, long id,Session session) throws HibernateException{
   return (FooObject)session.get(clazz,new Long(id));
}


First question: what is the difference between querying using Criteria and loading using session.get()?

Second question: what should I do if I have to load object with composite identifier?

In following method I cant replace query by get :(
Code:
public FooObject getFooObject (Class clazz, long id, Session session) throws HibernateException{
   Criteria criteria = session.createCriteria(clazz);
   criteria.add(Expression.eq(“id”, new Long(id)));
   criteria.add(Expression.eq(“type”, new Long(id)));
   return (Executor) criteria.uniqueResult();
}


NOTE: I'm using Hibernate 2.1.8

Is this problem appears in latest Hibernate version?


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.