HTTP Status 500 – Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.pbc.rsms.entity.UserInfo_$$_jvstcc6_0[“handler”]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.pbc.rsms.entity.UserInfo_$$_jvstcc6_0[“handler”])
Reason:
The problem is that with load method you get just a proxy but not the real object. The proxy object doesn’t have the properties already loaded so when the serialization happens there are no properties to be serialized. With the get method you actually get the real object, this object could in fact be serialized.
Method 1:
Add to the entity class generated by hibernate.
@JsonIgnoreProperties({“hibernateLazyInitializer”, “handler”})
Method 2:
load to get
I think that the problem is the way that you retrieve the entity.
Maybe you are doing something like this:
Person p = (Person) session.load(Person.class, new Integer(id));
Try using the method get instead of load
Person p = (Person) session.get(Person.class, new Integer(id));
The problem is that with load method you get just a proxy but not the real object. The proxy object doesn’t have the properties already loaded so when the serialization happens there are no properties to be serialized. With the get method you actually get the real object, this object could in fact be serialized.
Similar Posts:
- [Solved] Object references an unsaved transient instance – save the transient instance before flushing
- [Solved] org.hibernate.MappingException: Unknown entity: com.huangliusong.entity.Person
- [Solved] java.lang.ClassCastException: Ljava.lang.Object; cannot be cast to com.entity.Advertisem
- cannot simultaneously fetch multiple bags
- [Solved] Hibernate Error: org.hibernate.InstantiationException: No default constructor for entity
- [Solved] org.hibernate.hql.internal.ast.QuerySyntaxException: persons is not mapped…
- [Solved] org.hibernate.hql.internal.ast.QuerySyntaxException: persons is not mapped…
- [Solved] Mybatis Error: org.apache.ibatis.cache.CacheException: Error serializing object. Cause: java.io.NotSerializableExc
- org.hibernate.QueryException: could not resolve property
- MappedBy reference an unknown target entity property [How to Solve]