-->
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.  [ 2 posts ] 
Author Message
 Post subject: Update ModifiedBy column on update - Best Practice
PostPosted: Thu Dec 13, 2007 2:18 pm 
Newbie

Joined: Thu Dec 06, 2007 10:41 am
Posts: 3
Sorry, I posted this accidentaly in the wrong forum section but could not find a way to delete or move it.

My data object has a ModifiedBy attribute/column that should be updated every time a data object is changed. The column should be set to the id of the current user (stored in the session of my webapp).

I figured out several ways to implement this behavior so what I'm looking for is some sort of best practice advice:
a) Obviously I can't specify a default value in my HBM file as I do with the ModifiedOn timestamp column since I need to access a Java variable, or is there some way to use variables in this context?
b) use a saveOrUpdate Method in my DAO class, which is manually called on every change to set the value
c) use a preInsert/preUpdate event listener to set the values
d) use an interceptor to do so

I suppose this szenario is quite common so I hope that you can point me into the right direction or share your experience what worked best for you.

Thanks a lot,
Peter[/i]


Top
 Profile  
 
 Post subject: Re: Update ModifiedBy column on update - Best Practice
PostPosted: Sat Dec 15, 2007 7:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
WileE wrote:
[i]Sorry, I posted this accidentaly in the wrong forum
c) use a preInsert/preUpdate event listener to set the values


I would opt for the preInsert/preUpdate listeners. There is nice article on the ServerSide http://www.theserverside.com/tt/articles/article.tss?l=JPAObjectModel which uses JPA. Even if you are using Hibernate directly I think you should be able to get some ideas.


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