JPA(Hibernate)+Spring : no session or session was closed !请注意是非J2EE(web)下如何解决!如果是web项目,配置
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<param-name>entityManagerFactory</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
</filter>或者 <bean name="openSessionInViewInterceptor" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory"/>
</property>
</bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="vicky"/>
</bean>
可能我小白,因为我怎么看,上面的2种解决方案,只能解决J2EE下的(也就是web项目)...我现在只是J2SE...也就是说没有web.xml来配置Filter.也没有
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
<property name="mappings">
</property>因为J2SE没哪儿来的servlet!!!
请问,如何解决...
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<param-name>entityManagerFactory</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
</filter>或者 <bean name="openSessionInViewInterceptor" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory"/>
</property>
</bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="vicky"/>
</bean>
可能我小白,因为我怎么看,上面的2种解决方案,只能解决J2EE下的(也就是web项目)...我现在只是J2SE...也就是说没有web.xml来配置Filter.也没有
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
<property name="mappings">
</property>因为J2SE没哪儿来的servlet!!!
请问,如何解决...
Hibernate.initialize(object)加载吧
上下文也是一个对象,怎么只有web中才有呢?不是web程序也能加载spring文件吧
j2se可以加载spring啊...ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");