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.  [ 8 posts ] 
Author Message
 Post subject: Entity is saved ?
PostPosted: Mon Feb 25, 2008 1:38 pm 
Beginner
Beginner

Joined: Thu Nov 29, 2007 4:36 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,

I'm using NH 1.2 , and i'm trying to do : session.Lock(entity,LockMode). The problem i'm having , is that there's no way I can find to check if the entity has already been attached to the session.

I found an IsSaved method, but it's in SessionImpl class. When i reattach an already attached entity it throws an error ( cause it just couldn't fail silently? ). The solution for now is a try{}catch{} - and leaving it like that would suck.


Another question I have is : How can I force NH to not load a subentity from cache. (like Client.ClientDetails - ClientDetails does not have the update-ed information. )
.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 6:41 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I think ISession.Contains(object entity) can help you check whether your entity is already in the session.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 1:14 am 
Beginner
Beginner

Joined: Thu Nov 29, 2007 4:36 am
Posts: 20
Hmm, thanks, didn't see that :).

My problem turned out to be another, I tried lock on a new entity , that had never been saved previously :|.

Thanks for the help mate.


And for my second question : How can I force NH to not load a subentity from cache. (like Client.ClientDetails - ClientDetails is loaded from Cache).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 4:38 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
You could use SaveOrUpdateCopy() rather than Lock(), that would let you give it either a transient or persistent entity, but we had problems with it (well over a year ago so I don't remember the details). For separate reasons we track whether an entity is transient or not ourselves, so we know whether to call Lock() or Save(). If you don't use assigned IDs, you could just check if the ID property has a value to know if it's transient or not.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 5:03 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I think that if you use assigned identifiers this should still work as long as you implement a version property.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 1:56 am 
Beginner
Beginner

Joined: Thu Nov 29, 2007 4:36 am
Posts: 20
Quote:
How can I force NH to not load a subentity from cache. (like Client.ClientDetails - ClientDetails is loaded from Cache) ?


Thanks for the info, for now Lock will do just fine. I already said that it was a simple mistake not checking if the entity was new or not .

How about the lazy loading thingy ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 2:04 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
sirrocco wrote:
Quote:
How about the lazy loading thingy ?


An unwise way would be to clear the cache, but that brings you in a lot of new troubles


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 3:04 pm 
Beginner
Beginner

Joined: Thu Nov 29, 2007 4:36 am
Posts: 20
Well, that's the only way I could do it up to this point. So if I can't find another way ..... Clear() will remain the only way :|


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