English 中文(简体)
LazyInitiization 春季例外,尽管工作开放。
原标题:LazyInitializationException in Spring in spite of working OpenSessionInView

I m试图学习春+Hibernate,我开始使用Hibernate的Lazy装载。 为此,我需要利用<代码>。 OpenSessionInViewFilter 。

我认为,该组合是完全正确的,但我把它 past在后面。

当我试图装上某些<代码>@ 1 P-4, 1 P-3, 1 FS, 1 GS, 1 NS 页: 1

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: lessonScheduler.model.User.applicationses, no session or session was closed

但在解放的标志中,这似乎都是正确的。 本届会议开幕,第一级无问题(时序号<>16:43:33,122<>/code>)。

但是,当我试图轻率地装上所提到的物体时,我就谈了上述例外。

从原木来看,我可以看到举行新的公开会议,但随后坠毁。 我不知道为什么......

INFO: 16:43:32,439 DEBUG OpenSessionInViewFilter:239 – Using SessionFactory  sessionFactory1  for OpenSessionInViewFilter
INFO: 16:43:32,439 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  sessionFactory1 
INFO: 16:43:32,439 DEBUG OpenSessionInViewFilter:181 – Opening single Hibernate Session in OpenSessionInViewFilter
INFO: 16:43:32,439 DEBUG SessionFactoryUtils:316 – Opening Hibernate Session
INFO: 16:43:32,439 DEBUG SessionImpl:220 – opened session at timestamp: 13215446124
INFO: 16:43:32,470 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  userController 
INFO: 16:43:32,548 DEBUG AbstractBatcher:366 – about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
INFO: 16:43:32,548 DEBUG ConnectionManager:421 – opening JDBC connection
INFO: 16:43:32,548 DEBUG DriverManagerDataSource:162 – Creating new JDBC DriverManager Connection to [jdbc:mysql://webdev.felk.cvut.cz:3306/koukavoj]
INFO: 16:43:32,845 DEBUG SQL:401 – select this_.id as id3_0_, this_.firstName as firstName3_0_, this_.lastName as lastName3_0_, this_.login as login3_0_, this_.mail as mail3_0_, this_.password as password3_0_, this_.tel as tel3_0_ from koukavoj.user this_ where this_.id=? limit ?
INFO: Hibernate: select this_.id as id3_0_, this_.firstName as firstName3_0_, this_.lastName as lastName3_0_, this_.login as login3_0_, this_.mail as mail3_0_, this_.password as password3_0_, this_.tel as tel3_0_ from koukavoj.user this_ where this_.id=? limit ?
INFO: 16:43:32,987 DEBUG AbstractBatcher:382 – about to open ResultSet (open ResultSets: 0, globally: 0)
INFO: 16:43:33,002 DEBUG Loader:1173 – result row: EntityKey[lessonScheduler.model.User#1]
INFO: 16:43:33,025 DEBUG AbstractBatcher:389 – about to close ResultSet (open ResultSets: 1, globally: 1)
INFO: 16:43:33,025 DEBUG AbstractBatcher:374 – about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
INFO: 16:43:33,040 DEBUG TwoPhaseLoad:107 – resolving associations for [lessonScheduler.model.User#1]
INFO: 16:43:33,078 DEBUG TwoPhaseLoad:206 – done materializing entity [lessonScheduler.model.User#1]
INFO: 16:43:33,079 DEBUG StatefulPersistenceContext:790 – initializing non-lazy collections
INFO: 16:43:33,080 DEBUG ConnectionManager:302 – transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
INFO: 16:43:33,115 DEBUG OpenSessionInViewFilter:207 – Closing single Hibernate Session in OpenSessionInViewFilter
INFO: 16:43:33,116 DEBUG SessionFactoryUtils:789 – Closing Hibernate Session
INFO: 16:43:33,117 DEBUG ConnectionManager:441 – releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
INFO: 16:43:33,122 DEBUG ConnectionManager:302 – transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
INFO: 16:44:42,721 DEBUG OpenSessionInViewFilter:239 – Using SessionFactory  sessionFactory1  for OpenSessionInViewFilter
INFO: 16:44:42,722 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  sessionFactory1 
INFO: 16:44:42,723 DEBUG OpenSessionInViewFilter:181 – Opening single Hibernate Session in OpenSessionInViewFilter
INFO: 16:44:42,723 DEBUG SessionFactoryUtils:316 – Opening Hibernate Session
INFO: 16:44:42,724 DEBUG SessionImpl:220 – opened session at timestamp: 13215446827
INFO: 16:44:42,735 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  userController 
INFO: 16:44:42,737 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  userController 
INFO: 16:44:42,738 DEBUG DefaultListableBeanFactory:242 – Returning cached instance of singleton bean  userController 
INFO: 16:44:42,744 ERROR LazyInitializationException:19 – failed to lazily initialize a collection of role: lessonScheduler.model.User.applicationses, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: lessonScheduler.model.User.applicationses, no session or session was closed

网络:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

  <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
      <param-name>sessionFactoryBeanName</param-name>
      <param-value>sessionFactory1</param-value>
    </init-param>
    <init-param>
      <param-name>singleSession</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>*.xhtml</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

如果有人看一看 log或conf,我将不胜感激。

预 收

最佳回答

该实体的负荷为16:43:32

INFO: 16:43:32,845 DEBUG SQL:401 – select this_.id as id3_0_, this_.firstName as firstName3_0_, this_.lastName as lastName3_0_, this_.login as login3_0_, this_.mail as mail3_0_, this_.password as password3_0_, this_.tel as tel3_0_ from koukavoj.user this_ where this_.id=? limit ?

装货的会议于16:43:33时闭幕:

INFO: 16:43:33,115 DEBUG OpenSessionInViewFilter:207 – Closing single Hibernate Session {...}

另一届会议于16:44:42开幕:

INFO: 16:44:42,723 DEBUG SessionFactoryUtils:316 – Opening Hibernate Session

是在<>第二个<>期间举行的。 您的首选例外。 这一点是有意义的,因为你所装物体的解放会议在第一次自由会议于16:43:33时结束。

INFO: 16:44:42,744 ERROR LazyInitializationException:19 – failed to lazily initialize a collection of role: lessonScheduler.model.User.applicationses, no session or session was closed

由于我看上你的代码,我不得不猜测,你在物体投放之后,要么在控制人员开会或申请范围领域,要么可能在吉大港山区会议上,就把物体提上。

You should either preload the data you need when you initially load it from the database (by calling the lazy getter when the object is initially loaded, before that first session is closed) OR you should store only the KEY in the field/HTTP session, and reload the object in the subsequent request so the object still has a live Hibernate session associated with it when you call the lazy getter.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签