After upgrading my web application from spring boot 1.5.10 to spring boot 2.0.0 I ran into some runtime exceptions when accessing single entities.
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
My Repository:
public interface MyRepository extends JpaRepository<MyEntity, Long> {
}
In one of my services I called in spring data 1.x myRepository.findOne(id);
to fetch a single entity. But the method findOne(Long id) was removed in spring data 2 so I had to switch to another method.
I found JpaRepository#getOne(ID id);
After switching findOne
to getOne
all tests passed and were green. But during runtime I received the above mentioned exception. org.hibernate.LazyInitializationException
So I searched again for suitable methods and found CrudRepository#findById(ID id)
This time all worked out and I am happy, but the question is now, why do I get the org.hibernate.LazyInitializationException
when using getOne()
?