Announcement Announcement Module
No announcement yet.
SpringSessionSynchronization closes connection managed by other transaction manager Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpringSessionSynchronization closes connection managed by other transaction manager

    We have a problem when trying to use separate transaction managers from the same thread. From what we can see, the main problem lies in SpringSessionSynchronization.suspend() where the old session is closed although this would not be necessary.

    The two DB connections are configured via JNDI
    • main: used by the main business logic, uses JpaTransactionManager
    • journal: used to store meta-information on business processes (user, changes to underlying data, ...), uses HibernateTransactionManager

    The transaction boundaries are configured via AOP and a new transaction is opened when calling a service method. The business processing uses the main connection. During service execution, we write to the journal using the journal connection whenever something relevant happens. Every journal call uses a new transaction, so that the information is written to the journal, independent of whether main is rolled back or not.

    The problem occurs, if we
    1. have already made some changes in main,
    2. journal something using journal, and
    3. roll back the transaction on main

    Example in Code
    public void myServiceMethod() throws BusinessException {
    	journalSomething("We have changed something");
    	if (checkOtherCondition()) {
    		throw new BusinessException("There was a problem");
    	journalSomething("Everything ok");
    As soon as the transaction in journal is opened, the main transaction is suspended and, as a SpringSessionSynchronization is used for synchronization, the session is disconnected. As a result, everything changed during main up to step 2, is flushed to the DB, and - as you might suspect - not rolled back.

    Note: one problem may be that our connection is set to auto-commit. This is usually disabled correctly as soon as we get the session, but we would have to make a more detailed look to rule this out.

    Is there a way to avoid closing the session when suspending it? We are sure that we cannot interfere with that other session when writing to the new session in journal. Do we have to do something differently for our setup?

    This specific change has been introduced in the context of SPR-4077 for JBoss and seems to me like a hack without an off switch. Even the most recent version of this code using Hibernate 4 states the support for JBoss "on_close" release mode as reason. Is there a way to work around this?

    We are currently using
    • Hibernate 3.5.6
    • Spring 3.0.5
    • Tomcat 6.0.x

    Thank you very much,