• Post Reply Bookmark Topic Watch Topic
  • New Topic

TransientObjectException  RSS feed

 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!