-->
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.  [ 1 post ] 
Author Message
 Post subject: EmptyInterceptor for onFlushDirty
PostPosted: Wed Sep 24, 2008 9:48 am 
Newbie

Joined: Fri Feb 29, 2008 7:05 am
Posts: 13
Location: New Delhi, India
Hi All,

I did some POCs with EmptyInterceptor. I am facing different behavior of the same code in onSave & onFlushDirty.

Code:
public boolean onSave(Object entity, Serializable id, Object[] state,
         String[] propertyNames, Type[] types) {

      

      A a = (A) entity;

      // B   
               B b1 = new B();
      b1.setA(a);

      B b2 = new B();
      b2.setA(a);

      Set<B> bs = new HashSet<B>(0);
      bs.add(b1);
      bs.add(b2);

      
      for (int i = 0; i < propertyNames.length; i++) {
         if ("bs".equals(propertyNames[i])) {

            state[i] = bs;
         }
      }

      return super.onSave(entity, id, state, propertyNames, types);
   }


The above code works fine in onSave. However, when i try to do a similar thing in onFlushDirty then it is not happening i.e. I am not able to persist child of the entity A when I persist a using the interceptor.

In the onFlushDirty, I add the child objects on the "currentState". Since I got a class cast exception in onFlushDirty, I tried following but that even did not work, though did not get an exception this time.
Code:
a.getBs().add(b1);
a.getBs().add(b2);

for (int i = 0; i < propertyNames.length; i++) {
         if ("bs".equals(propertyNames[i])) {

            currentState[i] = a.getBs();
         }
      }




Am I missing here or is there any other way to do this in which I can just call a interceptor/listener on a particular entity and can do things just before it is being persisted.

Thanks for the help
Regards,
Nitin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.