-->
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: Detaching objects within a Session
PostPosted: Wed Jul 12, 2006 1:00 pm 
Beginner
Beginner

Joined: Fri Feb 17, 2006 1:28 pm
Posts: 24
Hello All,

I need to do the following and im not quite sure how to do it. I need to retrieve an object from the database using "load", once I have the object I want to detach it from the Session (I tried to use evict, but it didn’t work!), then change its values WITHOUT persisting it with the Database. If the user accepts the changes, I can then persist the object but not before.

Any ideas?

P.S. I also tried to flush and clear the Session but to no avail!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 3:28 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
I don't know if calling evict is a requirement for you or not, but what you could do is set this in Hibernate configuration (*.cfg.xml):

<property name="hibernate.connection.autocommit">false</property>

This means your object would not get updated until you explicitely called session.save or something like that. In this case you wouldn't need to call evict - you could just modify the object, and if your user wasn't happy with changes, then simply abandon changes. On the flipside, you'd need to always call session.something to persist your changes.

If you're running in transacted environment, you might also look at those config parameters:
hibernate.transaction.flush_before_completion
hibernate.transaction.auto_close_session

HTH,

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 13, 2006 1:38 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Sorry, I got confused there for a moment. This is the setting I was thinking of:

session.setFlushMode(FlushMode.NEVER);

This is the one that turns off auto-flush. So even when you close your session your data will not be persisted until you call session.flush();
That way your code can decide when to save and when to skip.

HTH,

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 13, 2006 2:41 pm 
Beginner
Beginner

Joined: Fri Feb 17, 2006 1:28 pm
Posts: 24
Thanks for the replay,

I gave that a go, but didnt seem to help.

Any other ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 3:31 pm 
Newbie

Joined: Wed Aug 02, 2006 1:49 pm
Posts: 2
I'm also having the same problem: I need to de-persist an object. If evict doesn't do this, then what is it for? Any help would be absolutely amazing!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 4:43 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
Why not just throw it away? Hibernate won't do anything until you "commit" the underlying transaction. If you rollback you can safely throw away eveything.


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.