-->
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.  [ 5 posts ] 
Author Message
 Post subject: Undesired TransientObjectException
PostPosted: Tue Mar 02, 2010 1:56 pm 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
I'm getting a TransientObjectException when executing a query:

Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing

My criteria has an object reference that is unsaved, true, but I'm using it to query with. I don't want to save it to the database at all. The query is much like the findByExample, except I'm including an Order-by clause.

Any thoughts?


Top
 Profile  
 
 Post subject: Re: Undesired TransientObjectException
PostPosted: Tue Mar 02, 2010 10:19 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,

If you want to pass your entity into the query, you should make sure that your entity is saved, because hibernate will compare the primary key in your entity, unless you use findByExample


Top
 Profile  
 
 Post subject: Re: Undesired TransientObjectException
PostPosted: Wed Mar 03, 2010 4:37 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
I understand, but I can't use findByExample because it lacks the order-by. I'm using it to make me it a bit easier to query with - instead of having to write out the full where clause. I was hoping for a workaround.


Top
 Profile  
 
 Post subject: Re: Undesired TransientObjectException
PostPosted: Wed Mar 03, 2010 5:55 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
Actually, the criteria allows to add an Example. However, it doesn't work on subclasses when there's a discriminator in play. To me, this seems an omission in Hibernate.


Top
 Profile  
 
 Post subject: Re: Undesired TransientObjectException
PostPosted: Wed Mar 03, 2010 11:15 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Hibernate flushes the session before executing queries. So if there are any objects in your session pointing to transient istances, this exception is thrown.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.