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"])
原因:
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.
解决办法1:
在hibernate生成的实体类中加:
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
解决办法2:
load变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 loadPerson 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.
解决办法来源:http://stackoverflow.com/questions/24994440/no-serializer-found-for-class-org-hibernate-proxy-pojo-javassist-javassist