Announcement Announcement Module
Collapse
No announcement yet.
CMT + EJB (MDB) + Spring + Hibernate correct configuration? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • CMT + EJB (MDB) + Spring + Hibernate correct configuration?

    This is probably a very common issue discussed in many threads but I am still quite confused about the correct configuration.

    I have created an MDB with CMT which integrates with Spring by extending AbstractJmsMessageDrivenBean. I am using LocalSessionFactoryBean to integrate with Hibernate.

    1) I do not have a Spring TransactionManager as I want all transaction management to be performed by the container (CMT).

    2) I am using Hibernate through HibernateTemplate. (just so that it's mentioned)

    3) I would like to have the JTA transaction as the context for the Hibernate Session. Will Spring be able to support this?? I assume that its supported though SessionFactoryUtils as long as I have set a javax.transaction.TransactionManager on the SessionFactory. I can set the hibernate property transaction.manager_lookup_class=OC4JTransactionMa nagerLookup (yes I am using OC4J) to take care of that. Is flush_before_completion and auto_close_session hibernate parameters needed?

    4) I would also like to have aggressive connection release since I will have a JTA enabled transaction and XA data source from JNDI. I see that Spring sets ConnectionReleaseMode = on_close. Where does this come into play? Should I override it? Should I set it to auto so that it is delegated to TransactionFactory? I could set transaction.factory_class=CMTTransactionFactory and then have ConnectionReleaseMode = after_statement but is this supported by Spring's session management?? Keep in mind point 1 (I am not using any Spring transaction manager since I have CMT).

    In other words: is the following configuration correct?

    Code:
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/myDS" resource-ref="true"/>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.connection.release_mode">auto</prop>
                <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.OC4JTransactionManagerLookup</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
                ... (other unrelated properties) ...
            </props>
        </property>
        <property name="mappingResources" ref="hibernateMappingResources"/>
    </bean>

    There are many opinions in the net and the forums about this. Could someone from the Spring team please provide a correct configuration of hibernate properties and LocalSessionFactoryBean for the scenario described above?

    Thanks a lot for reading!

  • #2
    As a follow up, I just wanted to share my thoughts on this issue, in case anyone is interested. I described them in my blog

    Comment

    Working...
    X