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

not work with hibernate 5.2.11 #113

Closed
qinarmy-zoro opened this issue Sep 25, 2017 · 4 comments
Closed

not work with hibernate 5.2.11 #113

qinarmy-zoro opened this issue Sep 25, 2017 · 4 comments

Comments

@qinarmy-zoro
Copy link

com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer#initializeCollection 's

PersistentCollection not compatibility

@CodeingBoy
Copy link

Same here as well as #106 does. I'm using 5.2.12.Final.
I tried using 5.2.0 and 5.2.6, which got same error.

@reda-alaoui
Copy link
Contributor

FYI, I am using hibernate 5.2.12.Final with Jackson 2.9.3.
I have no issue.

I think you should be a little more specific if you want help.
A stack trace and your maven dependency tree to begin with for example.

@CodeingBoy
Copy link

Here's stack trace:

java.lang.NoSuchMethodError: org.hibernate.collection.spi.PersistentCollection.setCurrentSession(Lorg/hibernate/engine/spi/SessionImplementor;)Z
	com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer.initializeCollection(PersistentCollectionSerializer.java:329)
	com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer.findLazyValue(PersistentCollectionSerializer.java:293)
	com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer.serialize(PersistentCollectionSerializer.java:231)
	com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
	com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
	com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
	com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913)
	org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:286)
	org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:107)
	org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:271)
	org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:182)
	org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Here's maven denpendency tree:

[INFO] +- org.hibernate:hibernate-core:jar:5.2.12.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:compile
[INFO] |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.0:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.9.0:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.9.0:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.apache.struts:struts2-core:jar:2.5.13:compile
[INFO] |  +- org.freemarker:freemarker:jar:2.3.23:compile
[INFO] |  +- ognl:ognl:jar:3.1.15:compile
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.3.3:compile
[INFO] |  +- commons-io:commons-io:jar:2.5:compile
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.6:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.1:compile
[INFO] +- org.apache.tomcat:tomcat-servlet-api:jar:8.5.20:provided
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- com.microsoft.sqlserver:mssql-jdbc:jar:6.2.1.jre8:compile
[INFO] +- org.apache.poi:poi:jar:3.17:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] +- org.springframework:spring-context:jar:5.0.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.0.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:5.0.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:5.0.3.RELEASE:test
[INFO] +- org.mockito:mockito-core:jar:2.13.0:compile
[INFO] |  +- net.bytebuddy:byte-buddy:jar:1.7.9:compile
[INFO] |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.9:compile
[INFO] |  \- org.objenesis:objenesis:jar:2.6:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.2.0:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.5.0:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.javassist:javassist:jar:3.18.2-GA:compile
[INFO] +- org.hibernate.validator:hibernate-validator:jar:6.0.7.Final:compile
[INFO] |  \- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] +- org.aspectj:aspectjrt:jar:1.8.13:compile
[INFO] +- cglib:cglib:jar:3.2.6:compile
[INFO] |  +- org.ow2.asm:asm:jar:6.0:compile
[INFO] |  \- org.apache.ant:ant:jar:1.9.6:compile
[INFO] |     \- org.apache.ant:ant-launcher:jar:1.9.6:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:jar:2.9.4:compile
[INFO] |  +- javax.transaction:jta:jar:1.1:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.4:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] \- com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile

Here's how I config converter in Spring configuration class:

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(jacksonMessageConverter());
    }

    public MappingJackson2HttpMessageConverter jacksonMessageConverter(){
        Hibernate5Module module = new Hibernate5Module(sessionFactory);
        module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION);
        module.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING);

        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
        builder.modulesToInstall(module);

        MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(builder.build());
        return messageConverter;
    }

Note that this get occurred when trying reading collections.

@CodeingBoy
Copy link

CodeingBoy commented Feb 13, 2018

Also, I built an artifact with solution in #104. It seems works for this NoSuchMethodError.
But it triggers another error:

com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy - no Session (through reference chain: model.Bundle["items"]->org.hibernate.collection.internal.PersistentSet[0]->model.ShopItem["type"])
	com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
	com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351)
	com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
	com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727)
	com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
	com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145)
	com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107)
	com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)
	com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer.serialize(PersistentCollectionSerializer.java:253)
	com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
	com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
	com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396)
	com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913)
	org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:286)
	org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:107)
	org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:271)
	org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:182)
	org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

EDIT: Seems it's my problem, pls ignore.

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

4 participants