-->
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: Interceptor doesn't update values
PostPosted: Thu Mar 06, 2008 5:34 am 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Hi!
I'm having problems with an Hibernate Interceptor:

Here is the code I'm using:

Code:
public class UserLogInterceptorProxy extends EmptyInterceptor {
   
   public boolean onSave(Object entity,
            Serializable id,
            Object[] state,
            String[] propertyNames,
            Type[] types) {
      
      Client client = (Client) entity;
      client.setName("interceptor");
      client.setAddress("interceptor");
      client.setAlias("interceptor");
      
      return true;
   }
}


This is not what I really want to do, but I've set this values for test purpose.

After hibernate triggers the interceptor client is not saved with the new values I've set in the interceptor. It is saved with the values that were set before the interceptor was executed.

I've debugged Hibernate code and I see that when values are being replaced after interceptor execution, the values array contains the old values and are being replaced in the Client object so the result is the same object as the original.

I have followed this example: http://hibernate.javabeat.net/articles/ ... oduction/3

What do I have to replace in the onSave method to set the new values to Client? Do I have to update the state array instead of the entity object?

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 5:54 am 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Well, It seems that in fact is the state array what I have to update although I think it is the inverse of what Hibernate is supposed to be designed for, work with POJO objects and not with hardcoded code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 6:56 am 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Now I have another problem.

I need to update an object that has a many-to-one relation with the Client. The type of the column is ManyToOneType in the state array but I can't access to the entity mapped valued with this.

ManyToOneType user = (ManyToOneType) state[i];
user.

Is there a way to acces the relation values in the interceptor?


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.