Org.hibernate.HibernateException No session found to current THREAD_J2EE

Source: Internet
Author: User
1. Problem Description
Spring 3.2.6
Hibernate 4.2.0 org.hibernate.HibernateException No session found for current thread

2. Analysis:
Quoted from R1:getcurrentsession () only makes sense inside a scope of transaction. Need to declare a appropriate transaction manager, demarcate boundaries of transaction and perform data access inside It.

3. Solution:

3.1 ADD configuration in application context.

<aop:aspectj-autoproxy/> 

<bean id= "TransactionManager" class= " Org.springframework.orm.hibernate4.HibernateTransactionManager ">
	<property name=" sessionfactory "ref=" Sessionfactory "/>
</bean>
	
<tx:annotation-driven transaction-manager=" TransactionManager " > 
3.2 Add Spring ' s @Transactional annotation

        @Autowired
	private sessionfactory sessionfactory;

	/**
	 * @return Session Object
	 *
	/private Session currentsession () {return
		Sessionfactory.getcurrentsession ();
	}
	
	/**
	 * @param operator * *
	@Transactional public
	void Saveoperator (operator operator) {
		Currentsession (). Save (operator);
	}


References:
1:http://stackoverflow.com/questions/10459922/org-hibernate-hibernateexception-no-session-found-for-current-thread
2:http://www.iteye.com/problems/94825




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.