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.  [ 4 posts ] 
Author Message
 Post subject: Managing persistent collections with an Interceptor
PostPosted: Mon Jul 31, 2006 11:58 am 
Newbie

Joined: Tue Jun 28, 2005 6:27 am
Posts: 6
Hi everybody,

I've got some issues converting my code to do some automatic processing using an Interceptor. Let's say I'v got a class A with a persistent set called "children", containing objects of class B. When an object of class A is saved or updated I have to add some instances of B to the "children" set.
I thought I could use the onFlushDirty method and add objects to children:

public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types
) throws CallbackException {
B b = new B();
b.setKey("dummyKey");
b.setProperty1("dummy1");
b.setProperty2("dummy2");
((A)entity).getChildren().add(b);
}

This code doesn't work. I tried also this, with no success:

public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types
) throws CallbackException {
B b = new B();
b.setKey("dummyKey");
b.setProperty1("dummy1");
b.setProperty2("dummy2");
Set set = new HashSet(((A)entity).getChildren());
set.add(b);
((A)entity).setChildren(set);
}

Should I play with the currentState array values? Or the issue is in WHEN the flushDirty method is invoked?

Any help appreciated.

Regards,

lorenzo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 27, 2007 3:07 am 
Newbie

Joined: Mon Aug 27, 2007 2:43 am
Posts: 8
I am facing a similar problem.

Adding a new object in a persistent collection in the onFlushDirty method does not persist the addition.

Can somebody throw more light on this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 27, 2007 9:47 am 
Newbie

Joined: Fri Jul 06, 2007 10:01 am
Posts: 10
If you have mapped the parent-child relationships correctly & set the values for children, it will be persisted automatically. You do not have to use an interceptor to achieve this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 3:10 am 
Newbie

Joined: Mon Aug 27, 2007 2:43 am
Posts: 8
Try calling session.flush() before you do a commit. flush will synchronize the changes made in the interceptor with the database.


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