aspose file tools*
The moose likes Spring and the fly likes Having problem in Spring3 using hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Having problem in Spring3 using hibernate" Watch "Having problem in Spring3 using hibernate" New topic
Author

Having problem in Spring3 using hibernate

Ishant Agarwal
Greenhorn

Joined: Sep 09, 2011
Posts: 22
Hi!! Guys

I am new in Spring and try to create an application using hibernate 3.2 but it gives me an exception like

org.apache.jasper.JasperException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


My Dao bean are defined as:
<bean id="propertyConfigure"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"></bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>


My DaoImplementation class

package com.customercare.service;

import java.util.List;


import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.customercare.model.User;

@Repository
public class UserDaoImpl implements UserDao {
@Autowired
private SessionFactory sessionFactory ;

@Override
public void addUser(User user) {
sessionFactory.getCurrentSession().save(user) ;
}

@SuppressWarnings("unchecked")
@Override
public List<User> listUser() {
return sessionFactory.getCurrentSession().createQuery(" from user" ).list() ;
}

}


Pl help me out

Regards
ishant
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Did you start up a Transaction before you called that code. So I assume you have Service classes and on those methods are you using @Transactional and have <tx:annotation-driven/> in your xml?

The error is saying that there isn't a Transaction running and Hibernate cannot run without a Transaction running.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
Have you set up the OpenSessionInViewFilter in your web.xml ?


SCJP 5 , SCWCD 5, SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having problem in Spring3 using hibernate