【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 ...
随机推荐
- cmd命令查看局域网内计算机信息
ping [计算机名] ping -a [IP] nbtstat -a [IP] net view arp -a nslookup www.baidu.com 查看当前dns地址 tracert [I ...
- css实现图片闪光效果
1.这个效果是看到京东商城上的一个下效果,原本的思路是 用js控制一个图片在某张需要闪光的图片上重复出现,但是 网上找了一些资料,竟然是用css写的,真是太帅了!!! 2.原理:在需要闪光的图片前添加 ...
- 51 NOD 1384 全排列(STL 搜索)
1384 全排列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出一个字符串S(可能又重复的字符),按照字典序 ...
- Base64编码格式详解
什么是Base64? 按照RFC2045的定义,Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式.(The Base64 Content-T ...
- 迭代器iterator
现在接着上篇的,写一来标识vector 的元素的对象迭代器iterator: 还是通过具体代码举例: 下面我讲了一个我暑期团队的故事哦~~: #include<iostream> #inc ...
- 【leetcode】Combination Sum III(middle)
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- 【C语言】二维指针做形参
转自:http://hi.baidu.com/gpmzccqceabimqq/item/f499f057aa1520404eff208b 关键: 传入时强制类型转换 + 使用时自己手工寻址 今天写程序 ...
- 【python】datetime获取日期,前一天日期
1.获取字符串型当前日期 2016-10-09格式 import datetime today = datetime.date.today() #datetime.date类型当前日期 str_tod ...
- java获取客服端信息(系统,浏览器等)
String agent = request.getHeader("user-agent"); System.out.println(agent); StringTokenizer ...
- Java_内存管理String and Array
题目1.指出下列程序运行的结果 ()public class Example { String str = new String("good"); char[] ch = { 'a ...