Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyInitializationException after updating to Spring Boot #116

Open
GuiRitter opened this issue Apr 24, 2018 · 2 comments
Open

LazyInitializationException after updating to Spring Boot #116

GuiRitter opened this issue Apr 24, 2018 · 2 comments

Comments

@GuiRitter
Copy link

GuiRitter commented Apr 24, 2018

Hi everyone.

While testing this project, which I found here, I think I found a bug somehow related to Hibernate. I downloaded a Spring Boot demo from Spring Initializr, modified it a bit, incorporated code from that project and I got the following stack trace when trying to access some members from user.getManager():

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:155)
	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:268)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73)
	at com.example.demo.User_$$_jvstdbc_0.getAddress(User_$$_jvstdbc_0.java)
	at com.example.demo.DemoApplicationTests.testSerialize(DemoApplicationTests.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

The most important changes from that project to mine is the introduction of Spring Boot and newer dependencies versions. To reproduce, download the project from here, build with Maven and run the tests from src/test/java/com/example/demo/DemoApplicationTests.java. This exception is not thrown in the project I mentioned (when changing from user.getManager().getId() to user.getManager().getAddress()).

I'm not sure if it's a bug or if I'm doing something wrong/that wasn't supposed to be possible, because this is not the problem I'm trying to solve, but I thought I should post it anyway, since I've seen a recent need of easily reproducible use cases. I'm also not sure if this is the place to post this. If it isn't, please tell me where.

@cowtowncoder
Copy link
Member

Ok, if it's related to Jackson, Hibernate, this is a good place to report.

This module does not really have an active maintainer so not sure what can be done but maybe someone has an idea of what to do.

@hurelhuyag
Copy link

I know It is 3 years late. But I encountered a similar exception. I expected Hibernate5Module will ignore the property if the property is lazy and not loaded yet. Is this correct? I can't get this behavior. I created a very minimal project with no other dependencies for demonstration purposes. It seems related to the hibernate-enhance-maven-plugin. If I disable hibernate-enhance-maven-plugin it simply serializes as null.

https://github.com/hurelhuyag/demo-jackson-hibernate5-mininal/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants