org.hibernate.LazyInitializationException: could not initialize proxy - no Session
See original GitHub issueI want to use to hibernate level2 cache as flow config.
@Getter
@Entity
public class Personnel{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String name;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
private Post post;
}
Now for get object at the first time, all things are ok! (that means I want to load ‘post’ from personnel) But when I call this function for a second time, in my personnel object the ‘post’ is null and I get an error as below:
Caused by: java.lang.reflect.InvocationTargetException: null at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:323) ... 132 common frames omitted Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:146) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:259) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73) at org.model.core.Post_$$_jvstb54_2a.getId(Post_$$_jvstb54_2a.java)
Hibernate 5.2 Radisson 3.12.5 spring-boot 2.1.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
thanks It works very fine
Unable to reproduce, below is my test code: