I have the entity

public class MyEntity {

    Long id;

    Status status;

    Integer value;

    public Status getStatus() {
        return status;

    public Integer getValue() {
        return value;


public enum Status {

And there is a JpaRepository:

public interface MyEntityRepository extends JpaRepository<MyEntity, Long> {}

Now, there is a test case (outside of any transaction):

MyEntity entity = doSomeBusinesLogic();
entity = myEntityRepository.getOne(entity.getId());
assertEquals(1, entity.getValue()); // Works fine
assertEquals(Status.CREATED, entity.getStatus()); // Throws exception

So the access to the Integer works fine, but the access to the enum throws an org.hibernate.LazyInitializationException.

I got this error after migrating from Spring Boot 1.5 (with Hibernate 5.0) to Spring Boot 2.0 (with Hibernate 5.2).

One working solution is to do the above code inside of an read-only-transaction. But I need to understand why? And why have that changed from Spring Boot 1.5 to 2.0?

Any ideas? TIA!

0 Answers