Spring Management transaction configuration, results error: No Hibernate Session bound to thread, and Config does not allow creation of non-transactional One here this anomaly

Source: Internet
Author: User

Java.lang.IllegalStateException:No Hibernate Session bound to thread, and configuration does not allow Creati On the non-transactional one here this exception

This error, the reason for the internet is a big push, anyway, I this problem is because although I in spring to configure the transaction, the result of running the error, see the configuration is not any problem, are online case according to write code, or wrong, the results found is because I am taking spring serv Ice or DAO beans are taken in the wrong way.

  

Fooservice Fooservice = Ctx.getbean ("Xxxxdao", Fooservice.Class;
//cannot be directly inBeanThe target proxy object, but from the transactionbean, So the agent got spring //fooservice fooservice = (fooservice) ctx.getbean ("Fooservice");

---, such as the above spring is the Fooservice interface subclass Xxxfooservice Transaction Management, the original habit directly
Fooservice Fooservice = (fooservice) ctx.getbe An ("Fooservice"); --Fooservice is the bean in spring

In fact, it is the bean of the subclass Xxxfooservice, but this bean is not the spring transaction management, how to get the spring Managed bean, i.e.

Fooservice fooservice = Ctx.getbean ( "Xxxxdao" ,fooservice. class) --This Xxxxdao is Transactionproxyfactorybean Bean or its subclass bean (must take its subclass bean when it is abstract)
The first parameter above is the transaction bean, the second parameter is the proxy target object that we want (must use the interface class, not the concrete implementation class), so that the service to get the spring transaction management, correct the above error will not appear.

Spring Management transaction configuration, results error: No Hibernate Session bound to thread, and Config does not allow creation of non-transactional One here this anomaly

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.