-->
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.  [ 4 posts ] 
Author Message
 Post subject: Getting Session from HibernateContext within Interceptor
PostPosted: Thu May 05, 2005 12:05 pm 
Newbie

Joined: Wed Dec 17, 2003 12:31 pm
Posts: 9
Location: Kent, UK
Hi

Jboss-4.0.1sp1
Hibernate 2.1.6
SQL Server 2k

I am trying to use an Interceptor to generate an audit trail from within a HAR in JBoss.

In order to avoid an endless loop, I need to get a Hibernate Session which does not have the audit Interceptor attached to it. How am I able to do this from the Hibernate context?

I've tried to use HibernateContext.getSession() and HibernateContext.getUnmanagedSession() but they both seem to return an instance of Session that has the Interceptor attached, thus resulting in loops.

What approach should I use? Should I declare two Hibernate mbeans in the hibernate-service.xml, one with the interceptor attached, and one without?

Thanks in advance for any help...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Lol, we were just talking about that a few days ago. Currently there is not a "nice" way to do it. In the meantime, yes you could use two different session factories to acheive this.

I think eventually that you will just need to call the form of SF.openSession() taking an Interceptor and pass in a null. The session factory would then use the internal no-op interceptor.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 1:58 pm 
Newbie

Joined: Wed Feb 16, 2005 10:46 am
Posts: 13
Location: Lake Worth, FL
Steve,

If I define the following in my hibernate-service.xml file :

Code:
       <attribute name="SessionFactoryInterceptor">com.adcware.rcs.util.AuditLogInterceptor</attribute>


How do I get the interceptor from my session facade method such that I can set the hibernate session on the interceptor?

My session bean method is:


Code:
   public Branch createBranch(Branch branch, String microMarketId)
      throws HibernateException {
      Session hsession = _sessionFactory.getCurrentSession();
       MicroMarket microMarket = (MicroMarket) hsession.load(MicroMarket.class, microMarketId);
       branch.assignToMicroMarket(microMarket);
       hsession.save(branch);
       return branch;
   }   



Is the writing of the audit log records done in the same managed session as above or in a separate one that I have to open, begin tx, commit tx and close by myself?

Any help is greatly appreciated.

Many thanks in advance,
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 2:01 pm 
Newbie

Joined: Wed Feb 16, 2005 10:46 am
Posts: 13
Location: Lake Worth, FL
Forgot to add to the above post: JBoss 4.0.2, Hibernate 3.0.3 and letting JBoss manage all the transactions.

Joe


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