-->
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: Automatic Dirty Checking
PostPosted: Mon Jun 20, 2005 5:10 pm 
Newbie

Joined: Thu Jun 02, 2005 3:25 pm
Posts: 7
Location: Traverse City, MI
I feel like I may be missing something. Due to hibernate's success I am sure that my thinking must be flawed, when it comes to this automatic dirty checking process.

I am using the Springframework with Hibernate 3, and I am using a SessionPerRequest pattern. So any object that I retrieve through load(),find(), etc... the object is in a persistant state, therefore any changes to an entities properties are automatically written to the database, cool huh!

Well not so cool if I want to have a validator validate the object before performing the update. Kind of like this:

Code:
// Hibernate DAO
// calls load(Client.class,id) ;
Client cli = clientDAO.getFromId(id);
ClientValidator validator = new ClientValidator() ;

cli.setName("New Name");

if( validator.validateClient(cli) ) {

    // do something

    // store client info
    clientDAO.update(cli) ;

} else {

   // inform system invalid client

}



The problem is that the information is already changed by the time validator is called. Should I be rolling back, if the validator says it isn't a valid client.

This seems like it would generate uneccessary SQL statements for validation that I can perform at the code level.

Any suggestions would be greatly appreciated. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 10:42 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
You could detach the object first using session.evict(cli), then reattach it afterwards using session.lock(cli, LockMode.NONE), but I am not convinced your design is sound. How come you can load an object, have the user perform changes, then save those changes back to the database all in one request-response cycle?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 8:05 am 
Newbie

Joined: Thu Jun 02, 2005 3:25 pm
Posts: 7
Location: Traverse City, MI
Well when the form gets submitted that is one request. If someone changes the name of a client on the form and then submits it I would have to get an instance of that client object in order to perform the changes.


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.