-->
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.  [ 5 posts ] 
Author Message
 Post subject: CreateBy, ModifiedBy Imlementation
PostPosted: Sun Mar 18, 2007 12:47 pm 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
Hi
I while ago, I read a artikle in Dr.Dobbs, that stated that every table in a database should at least hav 4 columns, CreatedBy, ModifiedBy, CreatedDate and ModifiedDate. After that, I noticed from other writers that that statement is accepted as best practice.

Taking this into accont,, is there a "best way" to implement this when using NHibernate??




//regards
//lasse
//NHibernate newbe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 1:49 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
we implemented a class named ModifiedInfo and mapped it as component to each table. The we use the IInterceptor interface to implement an interceptor which sets the values of the fields. There is a sample in the NHibernate documentation. See http://www.hibernate.org/hib_docs/nhibernate/html/manipulatingdata.html#manipulatingdata-interceptors

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 5:37 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Personally, since I often have my domain running at several remote locations from the database server and I like to keep the date/times synched with the database server I open a new connection in my interceptor and execute GETDATE() against the db to get the current date/time from there before updating the entities.

Causes a performance hit, but it's worth it for me.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 11:57 am 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
luedi wrote:
we implemented a class named ModifiedInfo and mapped it as component to each table. The we use the IInterceptor interface to implement an interceptor which sets the values of the fields. There is a sample in the NHibernate documentation. See http://www.hibernate.org/hib_docs/nhibernate/html/manipulatingdata.html#manipulatingdata-interceptors

Regards
Klaus


This seems like a way to go, still I have a couple of questions. If I have a many-to-many relationship, will the "mapping table" also be updated, using this interface?? How to you specify the many-to-many relationship to contain columns for ModifiedInfo data.

//Regards
//Lasse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 12:29 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Assosciations will only be flagged as dirty if they have been modified. If you implement your interceptor similar to the one in this posting http://forum.hibernate.org/viewtopic.php?t=971049, anything that is dirty and implements the proper interface will get trapped and have its info updated.


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