-->
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.  [ 6 posts ] 
Author Message
 Post subject: Object in Session
PostPosted: Fri Jan 02, 2004 8:37 am 
Newbie

Joined: Tue Sep 23, 2003 7:02 am
Posts: 16
Hi I am new to hibernate and I am using it to perform a large transaction.

My problem occures when I load the same object in the same session and update the second object. This obviously fails. I was wondering if there was any way of determining if a object is already in session, I need to do this by specifiing a key other the the primary (query maybe). I have looked through the API and there does not seem to be anything obvious on the session interface.

Any help would be appreciated

Thanks Lee


Top
 Profile  
 
 Post subject: Re: Object in Session
PostPosted: Fri Jan 02, 2004 10:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
leetcooper wrote:
I was wondering if there was any way of determining if a object is already in session, I need to do this by specifiing a key other the the primary (query maybe).

No, only session.contains(Object).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 10:36 am 
Newbie

Joined: Wed Dec 31, 2003 3:34 pm
Posts: 5
Location: Toronto, Canada
Je suis un Hibernate newbie, but wouldn't using one of the caching options also address this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 11:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No, you can't check an object by a non primary key. Actually I can't understand why you need this : if you wnat an object, Hibernta will give it you (from DB or from cache).

What is doable by cache is :
- share object through several sessions
- share HQL queries (and it's underlying objects)

There is no way to query the "session" subset.

You may add this functionality yourself by implementing an appropriate net.sf.hibernate.Interceptor.

Quote:
Je suis un Hibernate newbie

Eheh, I was, and I'm still learning.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 12:06 pm 
Newbie

Joined: Tue Sep 23, 2003 7:02 am
Posts: 16
Thx for everyones replies....

Ok if there is no way to determine if an object is in session how do I make sure that I evict the object within the same session transaction before I reload it. I have tried evict and this does not seem to work... Should I also flush the session or lock the object ??????.....

Basically I just need a way to perform a large transaction which can handle the possibility of the same object being referenced during the transaction..... Is this an RTFM issue because if it is I would be greatful in someone can point me to a section on how to handle large complex transactions....

thx Lee


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
if (session.contains(myObject) {
  session.evict(myObject);
}


Evicting an object is not a good way to work. If you can avoid it, then do.

_________________
Emmanuel


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