I have tried to configure my hibernate session factory to use Jboss J2EE transactions but have been unsuccessful thus far. My problem is that I am using Lazy loading via the OpenSessionInView filter, but when I change to J2EE transactions, SessionFactoryUtils does not seem to be able to find my open session. My spring xml context configuration is pasted below:
Code:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:/ClassesDataSource</value></property>
</bean>
<bean id="jtaTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:/TransactionManager</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<ref bean="configBeanMappings"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.transaction.manager_lookup_class">
net.sf.hibernate.transaction.JBossTransactionManagerLookup
</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jtaTransactionManager"/>
</property>
</bean>
I think I have traced the issue down to the method below, but I am not quite sure what the proper behavior is when using a J2EE Transaction Manager.
Code:
private static Session getSession(SessionFactory sessionFactory, Interceptor entityInterceptor,
SQLExceptionTranslator jdbcExceptionTranslator,
boolean allowSynchronization, boolean allowCreate)
Thanks for your help!
Karl