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: Guidlines on SessionFactory scoped interceptor
PostPosted: Sat Apr 21, 2007 9:20 am 
Newbie

Joined: Thu Apr 12, 2007 7:20 am
Posts: 8
Hello :

I am using Hibernate 3.1 in managed CMT environment with JBoss 3.2.7. I have to implement a Audit Inteceptor for all the entities for setting modified date time and modified user. Since I have configured Hibernate to work in a managed environment, I am using the getCurrentSession() method in SessionFactory to get the session. Since getCurrentSession() will use the interceptor registered with the SessionFactory, I have to implement a SessionFactory scoped interceptor.

My concerns are :

1. Does the org.hibernate.Intercpetor interface methods onSave, onFlushDirty has to be synchronized for SessionFactoryScoped interceptor implementation since it is mentioned that SessionFactory scoped interceptors must be thread safe.
http://www.hibernate.org/hib_docs/v3/re ... vents.html

2. If it has to synchronized, can it become a performance bottleneck since at every Tx Commit / Rollback these synchronized methods wil be called for every object creation / modification and deletion ?

3. For the modified user information to be audited, I am planning to use a thread local to share the state across the sessions. Is any other elegant methods exists in the case of Session scoped intercpetor ?

4. Other than the method quoted above, is there any elegant method exists for auditing in a managed environment where getCurrentSession() is used instead of openSession() or opensession( Interceptor interceptor ) ? I read about events but the same issues with threading and state exists in that approach also and intercpetor seemed simpler to me.

Am I missing something since I have searched the doc and forum and did not find answer to the above queries. Any pointers / guidance will be really helpful.

thanks and regards,
zeta


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 11:26 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You certainly would not want those methods to be synchronized, but that doesn't mean you can't make them thread safe. Just make sure you aren't storing any state in the interceptor that would ruin concurrent access.

Storing your user information in a ThreadLocal and retrieving it in the interceptor should be OK and you won't have to synchronize anything.


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.