【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 ...
随机推荐
- 使用phpmyadmin修改XAMPP中MySQL的默认空密码
XAMPP是开发php应用的一套完整的工具合集,就像安装软件一样安装,其他的都配置好了,不用自己再去繁琐的单独配置Apache.MySQL.php这几个模块了,以前我一直在使用的是Appserv,也是 ...
- MySQL字符集转换引发插入乱码问题
根据http://www.cnblogs.com/cchust/p/4601536.html进行验证测试 问题背景 在mysql上面执行一条普通的insert语句,结果报错: Incorrect st ...
- ssm控制输出sql(二)
望时高科联通log4j # DEBUG,INFO,WARN,ERROR,FATAL LOG_LEVEL=DEBUG ---------这里对应sql的级别 log4j.rootLogger=${LOG ...
- UVA 11827 Maximum GCD
F - Maximum GCD Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Given the ...
- storyboard pushViewController 的时候,新的界面黑屏
storyboard 创建的一级界面需要通过代码跳转到另一 storyboard 创建的界面的时候,通常我们会这样 其实 alloc init 相当于重新创建一个界面,所以我们 push 进入之后会发 ...
- 【2016-08-21】Linux内核版本编号规则简介
我们已经了解可以使用下面的几天命令来查看Linux内核版本及Ubuntu发行版本的信息: uname -r uname -a cat /proc/version lsb-release -a 等等 可 ...
- Redis事件管理(一)
Redis统一的时间管理器,同时管理文件事件和定时器, 这个管理器的定义: #if defined(__APPLE__) #define HAVE_TASKINFO 1 #endif /* Test ...
- JS判断IE版本并在页面显示内容
<script type="text/javascript"> var isIE = function (ver) { var b = document.createE ...
- 浅析 - iOS应用程序的生命周期
1.应用程序的状态 状态如下: Not running 未运行 程序没启动 Inactive 未激活 程序在前台运行,不过没有接收到事件.在没有事件处理情况下程序通 ...
- 瞧一瞧迷一般的SQLDA
With static SQL, host variables used in embedded SQL statements are known at application compile tim ...