【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】

报错:

1 HTTP Status 500 - Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered
2 to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.agen.entity.Product_$$_jvst2a_3["handler"]);
3  nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no
4 properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.agen.entity.Product_$$_jvst2a_3["handler"])

出现这个问题,是因为:

 1 @ResponseBody
 2     @RequestMapping("/Updateproduct")
 3     @Transactional
 4     public Product updateProduct2(Product product){
 5         Product  product1 = productService.load(product.getProductId());
 6         if(product1 != null){
 7             product1.setProductName(product.getProductName());
 8             product1.setProductCre(product.getProductCre());
 9         }
10
11         return product1;
12     }

这个方法中使用的load()获取到数据库中的这一条数据。

使用load()时,进入BUG模式可以看到,虽然获取到这条数据,但是你要看,却发现展示出来的这个对象的字段都是null。

但是其中是有值的!!

这样返回给前台,前台接收不到值,会跑出异常:

修改:

于是我们应该将load()方法修改为get()方法

 1 /**
 2      * 进行产品修改操作
 3      * @return
 4      */
 5     @ResponseBody
 6     @RequestMapping("/Updateproduct")
 7     @Transactional
 8     public Product updateProduct2(Product product){
 9         Product  product1 = productService.get(product.getProductId());
10         if(product1 != null){
11             product1.setProductName(product.getProductName());
12             product1.setProductCre(product.getProductCre());
13         }
14
15         return product1;
16     }

这样就能解决这个问题!!

时间: 2024-11-11 00:16:39

【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】的相关文章

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.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to cre

hibernate报错:Column 'id' cannot be null

报错内容: 17:21:59,843  INFO org.hibernate.tool.hbm2ddl.SchemaExport:226 - Running hbm2ddl schema export 17:21:59,859 DEBUG org.hibernate.tool.hbm2ddl.SchemaExport:242 - import file not found: /import.sql 17:21:59,859  INFO org.hibernate.tool.hbm2ddl.Sch

>Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap

>Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap web 项目中 打开 hibernate.cfg.xml 文件时 提示:The project is not a myEclipse hibernate project. 并且:在 dbbrower中使用 hibernate reverse engineering 建立 表对应的bean 和 配置文件时:找不到可用的

hibernate报错:no currentsessioncontext configured!

使用hibernate框架时候报错:no currentsessioncontext configured! 这个错误是当我们使用getCurrentSession();时候引起的,原因是currentSession配置错误,与事务有关,当我们使用currentSession的时候需要在hibernate.cfg.xml中进行如下事务配置: 1.如果是本地事务: <property name="hibernate.current_session_context_class">

hibernate报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: priva

Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法

报错信息: org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing load command : org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.weixin.db.model.Adminusers#15] 报错分析: Hibernate的映射

Django报错 The serializer field might be named incorrectly and not match any Got AttributeError when attempting to get a value for field `author_for` on serializer `KnownledgeBaseListSerializer`

1.问题描述,在设置,model部分字段的serialier时,出现如下报错 字段如下: 1 # 知识库List 2 class KnownledgeBaseListSerializer(serializers.ModelSerializer): 3 article_state = serializers.CharField(source='get_article_state_display') 4 know_classify = serializers.CharField(source='kn

hibernate报错:could not parse mapping document from resource

昨晚在自己电脑上搭建的ssh环境运行好好的,搭建成功的时候我还小兴奋了下,然后今天放到公司的电脑上去,直接给我报了个could not parse mapping document from resource,当时我那小心肝直接碎了,并且这个错误还让我改了几个小时,最后在http://blog.csdn.net/mydeman/article/details/6134820 发现了答案,*.hbm.xml中引用了错误的DTD文件路径“http://www.hibernate.org/dtd/hi

spring 项目tomcat 8.0.2 发布报错:Could not initialize class org.hibernate.validator.engine.ConfigurationImpl

tomcat 8 项目发布遇到的错 1 [ERROR] 2015-05-22 22:51:38,683 org.springframework.web.servlet.DispatcherServlet - Context initialization failed 2 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.valida