-->
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: Changing state in an Interceptor?
PostPosted: Mon Nov 14, 2005 1:50 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Hi,

Are Interceptors allowed to change the state of other objects in a graph that is being persisted? Here is what I'd like to do: Whenever a dirty object is persisted, I'd like to update its parent object (even if it wasn't dirty previously) and have these changes automatically persisted, as well. obviously, this assumes that Hibernate will persist child objects before parent objects, but I'm not sure if this is a safe assumption to make.

What are your thoughts?

Thanks!

Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 2:30 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try tell interceptor that save parent only from child, for example

static value saveParent=false;

...

in isTransient

public Boolean isTransient(Object entity) {
if (entity instanceof YourParent and !saveParent) {
return Boolean.FALSE;
}
return null;
}

in onSave

.. saving child
saveParent=true;
try {
save(parent);
} finally {
saveParent=false;
}
...

i don't try all, but it is idea
regards


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.