Hi. I am in the process of upgrading from Hibernate 3.6.10 to 4.1.8 and am encountering a few problems.
I am using Spring 3.2.3.RELEASE and Hibernate 4.1.8.Final, deploying on Glassfish 3.1.2 which has connection pools and datasource configured to connect to an Oracle 10g database.
The project itself is an EJB+WAR packaged in an EAR.
Spring configuration as follows:
For most part this works. I can deploy and it loads correctly and communicate with the database. However I have a couple of beans which call a factory-method such that they are initialized on startup and used repeatedly. The bean config is as follows:
paymentProviders:
With this and similar beans which make use of the factory-bean functionality the app stops working. When the first request goes through and the beans are being instantiated an exception is thrown.
Any idea what could be causing this and how to fix it?
I am using Spring 3.2.3.RELEASE and Hibernate 4.1.8.Final, deploying on Glassfish 3.1.2 which has connection pools and datasource configured to connect to an Oracle 10g database.
The project itself is an EJB+WAR packaged in an EAR.
Spring configuration as follows:
Code:
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDB"/>
</bean>
<tx:annotation-driven/>
<bean id="daoSupport" abstract="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.SunOneJtaPlatform</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
</props>
</property>
<property name="mappingResources">
<list>
...
</list>
</property>
</bean>
Code:
<bean id="providerManual"
class="com.test.payments.implementations.PaymentProviderManual" parent="providers">
<property name="paymentProviderData">
<bean factory-bean="paymentProviders" factory-method="byName">
<constructor-arg value="Manual"/>
</bean>
</property>
</bean>
<bean id="paymentProviders" class="com.test.lookups.PaymentProviders" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Code:
public class PaymentProviders {
private SessionFactory sessionFactory;
public PaymentProviderData byName (String name) {
return (PaymentProviderData) sessionFactory.getCurrentSession()
.createCriteria(PaymentProviderData.class)
.add(Property.forName("providerName").eq(name))
.uniqueResult();
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
Code:
[#|2013-07-11T14:23:35.411+0000|INFO|glassfish3.1.2|org.hibernate.dialect.Dialect|_ThreadID=35;_ThreadName=Thread-2;|HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect|#]
[#|2013-07-11T14:23:35.414+0000|INFO|glassfish3.1.2|org.hibernate.engine.transaction.internal.TransactionFactoryInitiator|_ThreadID=35;_ThreadName=Thread-2;|HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory|#]
[#|2013-07-11T14:23:35.415+0000|INFO|glassfish3.1.2|org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory|_ThreadID=35;_ThreadName=Thread-2;|HHH000397: Using ASTQueryTranslatorFactory|#]
[#|2013-07-11T14:23:35.931+0000|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=35;_ThreadName=Thread-2;|2013/07/11 14:23:35:931 UTC [INFO] HibernateTransactionManager - Using DataSource [com.sun.gjc.spi.jdbc40.DataSource40@3837437d] of Hibernate SessionFactory for HibernateTransactionManager|#]
....
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public com.test.payments.PaymentProviderData com.test.lookups.PaymentProviders.byName(java.lang.String)] threw exception; nested exception is org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
... 124 more
Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:88)
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:90)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:978)
at com.test.lookups.PaymentProviders.byName(PaymentProviders.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
... 125 more
|#]