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

Class cast exception on hibernate5 module #111

Closed
tomaldguz opened this issue Sep 14, 2017 · 6 comments
Closed

Class cast exception on hibernate5 module #111

tomaldguz opened this issue Sep 14, 2017 · 6 comments
Milestone

Comments

@tomaldguz
Copy link

I am getting this exeption when trying to serialize a a collection of objects with lazy collections as atributes:

com.fasterxml.jackson.databind.JsonMappingException: org.hibernate.internal.SessionImpl cannot be cast to javax.persistence.EntityManager (through reference chain: java.util.ArrayList[0]->com.checkout.model.Category["items"])

The problem is reproducible since 2.8.6 forward, using 2.8.5 I dont have this problem. I am working with spring and hibernate

I am initializing this way:

public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true); Hibernate5Module hibernateModule = new Hibernate5Module(sessionFactory().getObject()); hibernateModule.enable(Hibernate5Module.Feature.FORCE_LAZY_LOADING); objectMapper.registerModule(hibernateModule); jsonConverter.setObjectMapper(objectMapper); return jsonConverter; }

@cowtowncoder
Copy link
Member

Unfortunately Hibernate project has made a few incompatible changes to classes this module needs, so this may depend on version of Hibernate you are using.
So, which Hibernate version are you using?

@tomaldguz
Copy link
Author

I am using Hibernate 5.0.12, tried with 5.1.10 but had the same result.

@tomaldguz tomaldguz changed the title Class cast exeption on hibernate5 module Class cast exception on hibernate5 module Sep 14, 2017
@cowtowncoder
Copy link
Member

@tomaldguz Ok that's odd then. I thought it was 5.2 that was problematic. But maybe a PR to fix things for 5.2 broke 5.0/5.1 instead?

For Jackson 3.x I think we will deprecate this module since no one maintains it; it has been nothing but source of problems.

@tomaldguz
Copy link
Author

That would be a shame, I think it is a useful module, I will try to see if it works with 5.2.

@cowtowncoder
Copy link
Member

@tomaldguz Agreed. Would definitely like to see new contributors, any help is appreciated. Some of earlier work visible via PRs, may make sense to at-mention people who have worked.

mdahm pushed a commit to mdahm/jackson-datatype-hibernate that referenced this issue Aug 22, 2018
@mdahm mdahm mentioned this issue Aug 22, 2018
cowtowncoder added a commit that referenced this issue Aug 23, 2018
@cowtowncoder cowtowncoder added this to the 2.9.7 milestone Aug 23, 2018
cowtowncoder added a commit that referenced this issue Aug 23, 2018
…s 5.2+ incompatibility problems solved but closer
@cowtowncoder
Copy link
Member

Ok. So... fundamentally there is a big 5.1->5.2 problem with TransactionManager being moved to a different Java package. Reasons this may be a big problem is that it then changed signature of any method that has manager as return or argument type. Worst, it may not be a problem with compilation (i.e. to some degree may be source compatible -- depending on imports).

I made some changes to try to alleviate this, and tried running existing test suite (extra 5-2 compat).
Tests did not fail on ClassNotFoundError; and all standard tests passed for all 5.0 - 5.3 Hibernate versions.
But 5.2 test suite only passes on 5.2, 5.3, despite compiling on 5.1 and 5.0. I am not 100% sure if this is or is not a problem, but my gut feeling is that version 2.9.7 is much more likely to work with Hibernate 5.2.x and 5.3.x libraries. And there may be lurking issues for 5.0.x / 5.1.x.

Oh joy.

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

2 participants