• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

HibernateException:Could not obtain transaction-ynchronized Session for current thread

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are migrating from Spring 1.5 and Hibernate 3.X to Spring 4.X and Hibernate 4.x and we are getting the below exception,

[EXCEPTION CLASS: org.hibernate.HibernateException]
[ERROR CODE: N/A]
[EXCEPTION TIER: N/A]
[EXCEPTION CAUSE: null]
[EXCEPTION MESSAGE: Could not obtain transaction-synchronized Session for current thread]
[EXCEPTION STACK TRACE: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:993)
at VDaoImpl.getDAO(VDaoImpl.java:11)


Source Code :


Context file :

<bean id="VDao" class="VDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>DS</value>
</property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>

<bean id="commandHandlerDefaultProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>addCustomerTransactionCommandHandler</value>
<value>addCustomerCommandHandler</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>requiredTransactionInterceptor</value>
</list>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" />

<bean id="requiredTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

DAO Class:

Before Migration :
public class VDaoImpl extends HibernateDaoSupport

{
public VObj getVehicleByVIN(String name)
{
Criteria spCriteria = this.getSession().createCriteria(VDaoImpl.class);


return VObj;
}

}

After Migration :


public class VDaoImpl

{
private SessionFactory sessionFactoryNew;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactoryNew = sessionFactory;
}

public VObj getDAO(String name)
{
// Getting exception in the below line
Criteria spCriteria = his.sessionFactoryNew.getCurrentSession().createCriteria(VDaoImpl.class);


return VObj;
}

}

Any help appreciated.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you use the code tags.
https://coderanch.com/how-to/java/UseCodeTags
 
    Bookmark Topic Watch Topic
  • New Topic