Left and right Java "No bean named ' sessionfactory ' is defined" now often go out shh or within its framework SPING+JPA use the bottom hibernate annotation implementation; The reason for the exception is The Sessionfactory bean could not be found .
The reasons are for example the following:
1, in Many-to-one or Many-to-many time we set the fetchtype= "lazy" delay loading.
The solution to this problem is to add the Opensessioninview filter in Web. XML, the main function of Opensessioninviewfilter is to bind a hibernate session and the corresponding line threads of a complete request process. The goal is to implement the "Open Session in View" mode.
For example: it agrees
Delays loading the objects required to display after a transaction is committed.
The Opensessioninviewfilter filter binds the Hibernate Session to the request thread, and it is actively detected by Spring's transaction manager. So the opensessioninviewfilter is suitable for Service layer
(Among the filter-class note that I use hibernate so FILTER-CALSS:<filter-class> Org.springframework.orm.hibernate3.support.opensessioninviewfilter</filter-class>
Let's say you're using JPA:<filter-class> Org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class > )
<!--for handling delay load problems Opensessioninview filter, which must be configured before the Struts filter--><filter><filter-name> Opensessioninviewfilter</filter-name><filter-class> org.springframework.orm.hibernate3.support.opensessioninviewfilter</filter-class></filter>< filter-mapping><filter-name>opensessioninviewfilter</filter-name><url-pattern>/*</ Url-pattern></filter-mapping>
2, although the Opensessioninviewfilter has been added earlier. But also can be reported sessionfactory not defited;
The reason is very easy ———— name mismatch,opensessioninviewfilter mode uses bean.xml inside the bean id= "sessionfactory". Assuming that your sessionfactory bean is not called this name, it naturally reports that the bean cannot be found;
<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Java unusual problem no Bean named & #39;sessionfactory& #39; is defined and initialize a collection of role