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