[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2960) Add Interceptor to the openSession method the CurrentSessionContexts use

Shawn Clowater (JIRA) noreply at atlassian.com
Fri Apr 1 14:07:11 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=41941#action_41941 ] 

Shawn Clowater commented on HHH-2960:
-------------------------------------

Steve, in our case our interceptor is stateful in that it keeps track of out auditing entities and processes them as a batch so when we open a session we want a new interceptor each time.

We then piggy back off the connection() to join the transaction and write the audit records in the postFlush() of the interceptor.  This keeps the audit log records out of the main session and helps with flushing performance.

So, in essence we have 2 main cases where we have to deal with the interceptor, one where we override the protected Session buildOrObtainSession() in CurrentSessionContext to inject the Audit Interceptor into the Session obtained by the factory (that this patch allowed) 
The second is where we spin a session off inside the Interceptor in order to write the audit log records.  The session in that case would be w/o an interceptor of its own.

Both should still be possible with the Options stuff from the looks of it.  We have some more exotic uses of the connection() that I'm doing some deep soul searching on but they look like they'd be possible as well.

> Add Interceptor to the openSession method the CurrentSessionContexts use
> ------------------------------------------------------------------------
>
>                 Key: HHH-2960
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2960
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.2.5
>            Reporter: Shawn Clowater
>            Priority: Minor
>         Attachments: HHH-2960-3.3.SP1.patch, HHH-2960.patch
>
>
> Ran into a minor snag earlier where I was rigging up the stateful audit interceptor and didn't have a clean hook to jack the interceptor for my current session. 
> The sample code illustrates the use of the interceptor by using the sessionFactory.openSession(Interceptor) method and then goes on to say with the wave of a hand that if you're using the getCurrentSession functionality that you'll have to override  whatever CurrentSessionContext you're using.  That's a little bit more cumbersome that I was hoping for but to make matters worse the method that the ThreadLocalCurrentSessionContext is using to obtain the session is:
> public org.hibernate.classic.Session openSession(
> 			final Connection connection,
> 			final boolean flushBeforeCompletionEnabled,
> 			final boolean autoCloseSessionEnabled,
> 			final ConnectionReleaseMode connectionReleaseMode) throws HibernateException;
> There are no other constructors that I can see that combine all of these parameters with the addition of an Interceptor parameter.  It would be a nice to have if there were an overloaded method that accepted the addition of an Interceptor.
> I worked around it for now but I am ashamed at the way I'm storing state for my interceptor.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list