码迷,mamicode.com
首页 > 编程语言 > 详细

spring-data-jpa报错

时间:2019-11-12 00:53:50      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:spring   exce   引用   nbsp   原因   测试   highlight   lis   emd   

在测试多对多关联时报错:如果不是本文这个原因,请另寻他路。

ItemCategory category = new ItemCategory(2l,"cat1","1",1l,new Date(),null,null);
        ItemCategory category2 = new ItemCategory(1l,"cat1","1",1l,new Date(),null,null);
        List<ItemCategory> categories = new ArrayList<>();
        categories.add(category);
        categories.add(category2);
//        itemCategoryDao.save(category);
//        itemCategoryDao.save(category2);
        Item item = new Item("item1",1l,"item1path","itemdesc1",111l,1l,new Date(),null,categories);
        itemDao.save(item);

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.ruixun.yupoo.bean.ItemCategory; nested exception is java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.ruixun.yupoo.bean.ItemCategory

错误的翻译应该是:瞬时态对象异常(TransientObjectException),对象引用了一个没有报错的瞬时态实例(object references an unsaved transient instance

系统让你在保存item之前,先保存itemCategory。加上我的那个注释的就行了

 

spring-data-jpa报错

标签:spring   exce   引用   nbsp   原因   测试   highlight   lis   emd   

原文地址:https://www.cnblogs.com/5aixin/p/11839106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!