-->
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: Requiring properties (audit) to be set? (Not not null!)
PostPosted: Fri Aug 06, 2004 9:21 pm 
Newbie

Joined: Fri Jul 30, 2004 7:07 pm
Posts: 12
In various tables, we have several properies which MUST be entered in order to insert or update a row. For instance we have a property called log_user which tells us who the last person to make a change was.

Setting the property to not-null does not solve this as the prior value in the table is irrelevant. What we care about is that when a change is made, that the log_user field is set. Now the value could be the same as the old value (if the user is the same) so you can't simply just look for NO change in the value either.

The goal is to enforce this across most classes that are persisted in the system and detect when a developer missed something.

I can see two ways to address this:

1) After hibernate loads the object, reset the values to null. Then use a non-null property constraint which will complain when you store without updating the property. BUT, it does not look like there is a hook for an interceptor to be called after properties are loaded into an object (presumably because of lazy loading?).

This looks like the cleanest, most efficient method. Is there a way to do this?

2) Create a separate method to set the value of the member variable in the object which also sets a changed flag of sorts. This separate method is meant for developers versus the with original setter is only for hibernate only. Then create an interceptor which throws an exception if the flag is not set (or clears the flag so that subsequent reuse of the object will have the same behavior as new object). There might be some issues with inserts followed by updates here....

Any other ideas?

I know that a seperate log table would be a solution, but we don't have that luxury


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.