-->
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.  [ 10 posts ] 
Author Message
 Post subject: Can we get the loaded state?
PostPosted: Fri Feb 27, 2004 7:06 pm 
Newbie

Joined: Fri Feb 27, 2004 6:49 pm
Posts: 18
Location: Paris, France
We are putting our current application under Hibernate. In my old code I was having some complicated stuff allowing to keep what I called the original state of business objects, In fact it's a copy of my object right after it's loaded from the database. The object is then modified and in my business code I'm sometime comparing the initial and current values to see what has changed.

An example is: you send a client report only is your object went from a status to another.

Another is that you need to audit everything that changed and then put a String in DB with all that.

Now, I'm thinking about how I'm going to implement that in hibernate. I've notice that hibernate keeps a loaded state. Is there an API to access it? Does it fulfill my needs?

If not, does anybody have some ideas of how to do that?

One solution is to keep my copy system and adding an interceptor. BTW, how does hibernate creates the loaded state? I want the exact same thing (do not copy associations).

thanks,
Henri


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 8:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Look at Interceptor


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 8:32 am 
Newbie

Joined: Fri Feb 27, 2004 6:49 pm
Posts: 18
Location: Paris, France
Yeah, as I said it's what I will do unless there is a way where I don't have to code the initial state creation all by myself.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 10:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You may want to take a *closer* look at Interceptor. During onFlushDirty() you are passed the initial and current state of the entity


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 6:19 am 
Newbie

Joined: Fri Feb 27, 2004 6:49 pm
Posts: 18
Location: Paris, France
That's sound good. I'll take a *closer* look indeed. :-) Sorry to have missed the point the first time.


Top
 Profile  
 
 Post subject: How do I propagate a logged in user's security credentials?
PostPosted: Thu Mar 04, 2004 5:45 pm 
Newbie

Joined: Mon Feb 09, 2004 6:07 pm
Posts: 7
gavin wrote:
Look at Interceptor


I am currently in the process of implementing audit log functionality for our application. What I want to do is to create a new row in the audit table whenever an object's state is modified (more specifically, whenever data in certain columns is modified). However, I also need the logged in user who is modifying the data. How do I propagate this to the Interceptor? It does not take the javax.security.Principal as a method parameter.

Thanks for the great work on Hibernate...it is a wonderful persistence framework.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 6:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well, Interceptor is just an interface which *you* implement, right? That implementation can get a user in any way it needs to.

Maybe you pass it into the constructor for a session-level Interceptor. Personally, I pass a SessionFactory-level Interceptor an instance of an object which it can use to retreive the current user.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 1:44 pm 
Newbie

Joined: Mon Feb 09, 2004 6:07 pm
Posts: 7
May be I am doing something wrong, but my interceptor is never getting called. Here is how I am using the Interceptor.
Code:
session = sessionFactory.openSession(new MyInterceptor());

and in MyInterceptor, I am overrriding the onflushDirty() method, here are the first few lines, that just test if this method is ever getting called when an object is modified:
Code:
public boolean onFlushDirty(Object entity, Serializable serialId, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException {

        log.debug("onFlushDirty() method called");
        System.out.println("onFlushDirty() method called");       
        .....
        return false;

Here is my test code, where I modify a Hibernate generated object:
Code:
        Opportunity opp = LeadServices.getOpportunityByObjid(new BigDecimal(268545434));
        System.out.println("test_auditLog(): Name = " + opp.getName());
        opp.setRank(new BigDecimal(400));
        LeadServices.updateLead(opp);

As expected, Hibernate modifies the object and I can see the changes in database, but it looks like it never calls my interceptor's onFlushDirty() method (because it never prints the log/print statements I have at the beginning of that method).

Any help is highly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 2:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Somehow in your system, the "sessionFactory.openSession(new MyInterceptor());" call you think is happening is not happening...

As always, a simplified main() will help you track this down. Create a main() which opens a session in the fashion you describe then does the object modifications.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 2:23 pm 
Newbie

Joined: Mon Feb 09, 2004 6:07 pm
Posts: 7
Thanks steve. I found the problem. I used IDEA to generate the default implementation for the Interceptor interface methods and then just changed the onFlushDirty() method implementation. It turned out IDEA did not do a good job in implementing the defult behavior for the findDirty() method (it did not return null), and that's why the onFlushDirty() method never got called.


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