Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TransientObjectException

 
Magesh Lakshmi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a code like this.

List list = Collections.EMPTY_LIST;
sess = HibernateSessionFactory.currentSession();
Item item = new Item();
item.setItemName( itemName );

//WAY : 1
Query query = sess.getNamedQuery("findBidsForItem");
query.setEntity( "it", item );
list = query.list();

//WAY : 2
//Criteria criteria = sess.createCriteria( Item.class );
//criteria.add( Example.create( item ));
//list = criteria.list();


When i execute using WAY 1, I get this TransientObjectException, but when i execute it using WAY 2, everything works fine.

Can anyone please clarify this ?
 
Magesh Lakshmi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the problem.
Instead of creating an transient Item instance, we should have used
sess.load() to first load the instance and then use if for querying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic