java.lang.UnsupportedOperationException:试图序列化java.lang.Class:org.hibernate.proxy.HibernateProxy [英] java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy

查看:120
本文介绍了java.lang.UnsupportedOperationException:试图序列化java.lang.Class:org.hibernate.proxy.HibernateProxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ c 

$ c> carObjectDao = new GenericDAO< carObject>(carObject.class);
列出< carObject> allCars = carObjectDao.readAll();
Gson gson = new Gson();
String carString = gson.toJson(allCars);
System.err.println(carString);
返回carString;

我以调试模式运行应用程序,并且allCars正确地填充了数据,但在此之后出现异常抛出:

  java.lang.UnsupportedOperationException:试图序列化java.lang.Class:org.hibernate.proxy.HibernateProxy。忘记注册一个类型适配器? 

我不知道异常的根本原因

这是一个已知的问题:无法序列化HibernateProxy的对象原因



JSon无法反序列化HibernateProxy对象,因此您要么取消代理权限,要么删除em。



或者,您可以急于获取懒惰的数据。


I'm using a Restful web service (Jersy implementation) with a JSF application and used Json to get the data as follows:

    carObjectDao = new GenericDAO<carObject>(carObject.class);
    List<carObject> allCars = carObjectDao.readAll();
    Gson gson = new Gson();
    String carString = gson.toJson(allCars);
    System.err.println(carString );
    return carString ;

i run the application in debug mode and allCars is filled with the data correctly, but after that an exception is thrown :

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?

i don't know the root cause of the exception

解决方案

This is a known problem: Could not serialize object cause of HibernateProxy

JSon can't deserialize HibernateProxy objects, so you either unproxy or remove em.

Or, you can eager fetch the lazy data.

这篇关于java.lang.UnsupportedOperationException:试图序列化java.lang.Class:org.hibernate.proxy.HibernateProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆