-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to test if an object is Transient?
PostPosted: Wed Jul 26, 2006 8:30 pm 
Newbie

Joined: Thu Oct 06, 2005 8:08 pm
Posts: 19
How do I test if an object is transient? How do I update the object from the database only if it is transient or disconnected?

I save a Hibernate object representing the active logged in user in my web session. I'm getting sporadic TransientObjectException errors when I access it. I don't want to do a database hit every time I access that value.

Hibernate 3.2CR3


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 9:53 pm 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Accessing a detached entity shouldn't be a problem in most cases. The one situation where it will fail is if you have lazy-loaded relationships on that entity.

In any case, perhaps these will help you (from the hibby docs):

"The lock() method also allows an application to reassociate an object with a new session. However, the detached instance has to be unmodified!"

"It is possible to re-load an object and all its collections at any time, using the refresh() method. This is useful when database triggers are used to initialize some of the properties of the object." (It sound like you don't want to be reloading though.)

You might want to track down the exact cause of this TransientObjectException, because that doesn't strike me as something that would occur when using a detached instance.

_________________
-Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.