spring-data-jpa报错
Posted 5aixin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-data-jpa报错相关的知识,希望对你有一定的参考价值。
在测试多对多关联时报错:如果不是本文这个原因,请另寻他路。
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 boot配置spring-data-jpa的时候报错CannotCreateTransactionException: Could not open JPA EntityManager
错误记录Flutter 混合开发获取 BinaryMessenger 报错 ( FlutterActivityAndFragmentDelegate.getFlutterEngine() )(代码片段
springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found(代码片段
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段