[JPA] javax.persistence.EntityNotFoundException: Unable to find com.duona.base.bean.Business with id
2016-12-21 14:27
567 查看
根本原因:由于后来加上的实体、对象在之前的数据没有关联上,所以造成脏数据、故根本的解决方法,就是将之前的测试数据删除,重新添加数据就行了。
网上解决方法:
问题原因:
无论是@OneToOne 还是@ManyToOne,出现这个原因都是因为子表(被关联表)中没有主表(关联表)中ID所对应的记录。
解决办法:
1. 检查为什么子表中没有主表中ID对应的记录
2. 如果子表中没有主表ID对应的记录也可以正常加载数据,那么需要在主表字段上加一个@NotFound Annotation。示例如下:
@OneToOne(optional=false)
@JoinColumn(name="business_id")
@NotFound(action=NotFoundAction.IGNORE)
private Business business;
这样,当子表中没找到数据时,主表中对应的field就是null,而不会报错了。
网上解决方法:
问题原因:
无论是@OneToOne 还是@ManyToOne,出现这个原因都是因为子表(被关联表)中没有主表(关联表)中ID所对应的记录。
解决办法:
1. 检查为什么子表中没有主表中ID对应的记录
2. 如果子表中没有主表ID对应的记录也可以正常加载数据,那么需要在主表字段上加一个@NotFound Annotation。示例如下:
@OneToOne(optional=false)
@JoinColumn(name="business_id")
@NotFound(action=NotFoundAction.IGNORE)
private Business business;
这样,当子表中没找到数据时,主表中对应的field就是null,而不会报错了。
相关文章推荐
- [JPA] javax.persistence.EntityNotFoundException: Unable to find XXXX with id 0 问题原因
- [JPA] javax.persistence.EntityNotFoundException: Unable to find XXXX with id 0 问题原因
- [JPA] javax.persistence.EntityNotFoundException: Unable to find XXXX with id 0
- [JPA错误]javax.persistence.EntityNotFoundException: Unable to find xxx
- [JPA错误]javax.persistence.EntityNotFoundException: Unable to find xxx
- 关于 EntityNotFoundException: Unable to find Person with id 11
- JPA--Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mysqlJPA] Unable to configure EntityManagerFactory
- javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [co
- Neo4j查询报错:Unable to load NODE with id 或者 Neo.ClientError.Statement.EntityNotFound
- Solving “javax.naming.NameNotFoundException: Unable to resolve ‘jdbc.SOAAppUserDataSource’ “ with Oracle SOA Suite 11g Adapter S
- Android问题解决记录—android.content.res.Resources$NotFoundException: Unable to find resource ID
- android.content.res.Resources$NotFoundException: Unable to find resource ID 0#0xffffffff
- javax.persistence.EntityNotFoundException: deleted entity passed to persist:异常总结
- Android开发问题:ActivityNotFoundException: Unable to find explicit activity class
- Android开发问题:ActivityNotFoundException: Unable to find explicit activity class
- java.lang.ClassNotFoundException: javax.persistence.Entity
- hibernate java.lang.ClassNotFoundException: javax.persistence.EntityListeners
- 解决:ould not find a getter for porDate in class com.bc.bean.PortalSheet Caused by: org.hibernate.PropertyNotFoundException: Could
- java.lang.ClassNotFoundException: javax.persistence.EntityListeners
- EJB在weblogic下遇到的Exception:Exception in javax.naming.NameNotFoundException: While trying to lookup 'ejb.com/genuitec/trader/ejb/T