2

I'm using OpenSessionInViewInterceptor to avoid LazyInitializationException.

It worked fine, but from sometime LazyInitializationException occurs even I'm using OSIV. The exceptions are like this:

SEVERE: Servlet.service() for servlet [appServlet] in context with path [] 
    threw exception [Request processing failed; nested exception is 
    org.apache.tiles.impl.CannotRenderException: ServletException including path 
    '/WEB-INF/views/home/master.jsp'.] with root cause org.hibernate.LazyInitializationException: 
    failed to lazily initialize a collection of role: com..., 
    no session or session was closed 
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersisten
tCollection.java:383)
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(Abs
tractPersistentCollection.java:375)
        at 

More weird thing is that the exception log is only in log files and there's no problem to navigate web site.

How is this happen?

Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
  • Are you doing any threading in your application? Can you show the relevant part of the applicationContext.xml/web.xml where you set up the OpenSessionInViewInterceptor? It would also probably help to see the area of the code that's causing the exception to be thrown. – Tim Pote Apr 07 '12 at 18:03

2 Answers2

0

This usually happen when you work with a dettached object. You have to re-attach the object to a session so Hibernate can work with it.

Use session.merge() or session.refresh()

Here you have some examples too: What is the proper way to re-attach detached objects in Hibernate?

Community
  • 1
  • 1
Fisu
  • 2,534
  • 1
  • 15
  • 14
0

In my case, it was because of cached objects. As cached objects were detached LazyInitializationException occurred while accessing to some properties, which hasn't been initialized, later.

Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126