Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

I have 2 physical servers which my web application hits managed by load balancers. I always get -

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

when one of the servers are hit while the other one runs smoothly without any problems. I have a local managed cache store enabled and managed by the application. This exception happens only while trying to access one particular column from one table. The rest of the operations work absolutely fine regardless of which server is hit.

Making lazy=false will become a performance issue because the number of rows on that table is quite large. And by the way, we are using get(object) on session instead of load(object).

like image 967
Surya Mukerjee Avatar asked Oct 04 '11 22:10

Surya Mukerjee


1 Answers

From the tags you provided, I deduce you ran into this problem using Spring Framework. I ran into the same LazyInitializationException while using a Spring Data org.springframework.data.jpa.repository.JpaRepository.

I solved the problem by annotating the method which indirectly uses Hibernate to retrieve data from the database with @Transactional.

like image 178
Abdull Avatar answered Nov 12 '22 07:11

Abdull