-->
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.  [ 3 posts ] 
Author Message
 Post subject: session flushing control
PostPosted: Wed Jun 28, 2006 11:25 am 
Newbie

Joined: Tue Jun 27, 2006 9:02 pm
Posts: 1
Is there a way to config session "transparent write behind" behavior? If I want to only sync up session in memory objects that I called session.saveOrUpdate, not the in memory objects that I modified, how do I do that?

the reason I want to do this is because I want to generate event on every save call. I do not want hibernate to write behind transparently. Is there a way to do this?

We are using hibernate 3.1.3 and Spring framework.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 2:13 pm 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Quote:
If I want to only sync up session in memory objects that I called session.saveOrUpdate, not the in memory objects that I modified, how do I do that?

As far as I know, every attached object (meaning that the object obtained through the EntityManager) is going to be checked for changes at session flush time. So what's left for you is to detach the object. There are two ways to do that: use EntityManager.clear() to detach all objects; or get the Hibernate underlying session and evict() a single object. Call saveOrUpdate only after detaching objects. Note that an evited object is not guaranteed to not be saved if it is in a cascade chain.
Quote:
the reason I want to do this is because I want to generate event on every save call

You can achieve that by implementing an entity listener or an entity lifecycle callback method. Piece of cake if you're using annotations.
Consider thoroughly your objective before choosing an approach (these or others).

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject: Re: session flushing control
PostPosted: Wed Jun 28, 2006 2:32 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
ling_wang72 wrote:
the reason I want to do this is because I want to generate event on every save call. I do not want hibernate to write behind transparently. Is there a way to do this?


It is very easy to do. Hibernate 3 provides an easy-to-use event architecture. You can register a custom Interceptor if you want, or register for a particular event for example.

See http://www.hibernate.org/hib_docs/v3/re ... vents.html

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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