【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】
报错:
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.agen.entity.Product_$$_jvst2a_3["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.agen.entity.Product_$$_jvst2a_3["handler"])
出现这个问题,是因为:
@ResponseBody
@RequestMapping("/Updateproduct")
@Transactional
public Product updateProduct2(Product product){
Product product1 = productService.load(product.getProductId());
if(product1 != null){
product1.setProductName(product.getProductName());
product1.setProductCre(product.getProductCre());
} return product1;
}
这个方法中使用的load()获取到数据库中的这一条数据。
使用load()时,进入BUG模式可以看到,虽然获取到这条数据,但是你要看,却发现展示出来的这个对象的字段都是null。
但是其中是有值的!!
这样返回给前台,前台接收不到值,会跑出异常:
修改:
于是我们应该将load()方法修改为get()方法
/**
* 进行产品修改操作
* @return
*/
@ResponseBody
@RequestMapping("/Updateproduct")
@Transactional
public Product updateProduct2(Product product){
Product product1 = productService.get(product.getProductId());
if(product1 != null){
product1.setProductName(product.getProductName());
product1.setProductCre(product.getProductCre());
} return product1;
}
这样就能解决这个问题!!
【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】的更多相关文章
- 【实体 报错 】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer
HTTP Status 500 - Could not write content: No serializer found for class org.hibernate.proxy.pojo.ja ...
- No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer解决方法
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.poj ...
- No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer
异常信息如下所示: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for cla ...
- 异常处理:No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer
No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no pro ...
- org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.
2011-08-16 13:26:58,484 [http-8080-1] ERROR [core.web.ExceptionInterceptor] - org.codehaus.jackson.m ...
- Hibernate报错,关于配置的SessionFactory找不到问题
最近写项目使用hibernate默认的dtd,在启动项目时经常会出现这个问题,hibernate报错,配置factory的id找不到,找不到mapping配置文件, 不能读取配置的xml文件 Coul ...
- Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法
报错信息: org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing ...
- hibernate报错Unknown integral data type for ids : java.lang.String
package com.model; // Generated 2016-10-27 14:02:17 by Hibernate Tools 4.3.1.Final /** * CmDept gene ...
- Hibernate报错解决Error parsing JNDI name [],Need to specify class name
能实现写数据,但是报错. 出错信息: 十月 21, 2016 3:46:18 下午 org.hibernate.Version logVersionINFO: HHH000412: Hibernate ...
随机推荐
- 监控Tomcat解决方案(监控应用服务器系列文章分享)
使用JMX接口开发监控程序 ◆ 全部代码需要从零开始,代码量较大 ◆ 支持各不同版本比较麻烦,每个版本可能有差异 ◆ 可支配性强 ◆ 最重要的一个缺点是,配置比较麻烦 Tomcat激活JMX远 ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- Html5 新标签
⒈ <audio></audio> 定义声音<autoplay></autoplay> 该属性出现,音频就绪后马上播放<controls>& ...
- php数据访问(查询)
查询:常用关键字查询 和 准确查询 单条件查询 创建添加查询元素 <br /> <form action="main.php" method="post ...
- 如何查看设备的 UDID
手机连接上电脑,打开 Xcode,确认手机已连上: command+shift+2,就可以查看到 UDID 了:
- [Android Pro] 将你的安卓手机屏幕共享到PC或Mac上
有时候为了方便演示一个手机app,需要把手机屏幕显示到PC或Mac上.这里提供一个方法 — 使用Vysor达到此功能. Vysor的吸引力在于3个方面: 它适用于Windows.Linux或Mac. ...
- Warp divergence
Threads are executed in warps of 32, with all threads in the warp executing the same instruction at ...
- Swift - 多行文本输入框(UITextView)
1,多行文本控件的创建 1 2 3 4 let textview = UITextView(frame:CGRect(x:10, y:100, width:200, height:100)) text ...
- NYOJ题目813对决
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAALRCAIAAAAiJ3lxAAAgAElEQVR4nO3dPW7jSgMu6LsJ516IYy
- 整理 iOS 9 适配中出现的坑(图文)(转)
作者:董铂然 本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着 ...