Skip to content

Class cast exception on hibernate5 module #111

@tomaldguz

Description

@tomaldguz

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; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions