[JPA] javax.persistence.EntityNotFoundException: Unable to find XXXX with id 0
2013-11-01 21:55
756 查看
[JPA] javax.persistence.EntityNotFoundException: Unable to find XXXX with id 0
解决办法是:原因: 无论是@OneToOne 还是@ManyToOne,出现这个原因都是因为子表(被关联表)中没有主表(关联表)中ID所对应的记录。
解决办法: 1. 检查为什么子表中没有主表中ID对应的记录 2. 如果子表中没有主表ID对应的记录也可以正常加载数据,那么需要在主表字段上加一个@NotFound Annotation。示例如下: @OneToOne(optional=true )
@JoinColumn(name="companyId",insertable=false, updatable=false)
@NotFound(action=NotFoundAction.IGNORE)
private Company company; 这样,当子表中没找到数据时,主表中对应的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 com.duona.base.bean.Business with id
- [JPA错误]javax.persistence.EntityNotFoundException: Unable to find xxx
- [JPA错误]javax.persistence.EntityNotFoundException: Unable to find xxx
- 关于 EntityNotFoundException: Unable to find Person with id 11
- Neo4j查询报错:Unable to load NODE with id 或者 Neo.ClientError.Statement.EntityNotFound
- javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [co
- android.content.res.Resources$NotFoundException: Unable to find resource ID 0#0xffffffff
- Solving “javax.naming.NameNotFoundException: Unable to resolve ‘jdbc.SOAAppUserDataSource’ “ with Oracle SOA Suite 11g Adapter S
- JPA--Caused by: javax.persistence.PersistenceException: [PersistenceUnit: mysqlJPA] Unable to configure EntityManagerFactory
- Android问题解决记录—android.content.res.Resources$NotFoundException: Unable to find resource ID
- javax.persistence.EntityNotFoundException: deleted entity passed to persist:异常总结
- ofbiz添加物品到购物车失败Could not find a valid price for the product with ID [XX-XXXX], not adding to cart.
- Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity
- Hibernate JPA —— Unable to find ... with id 0 错误
- android.content.ActivityNotFoundException: Unable to find explicit activity class解决办法
- Hibernate初学时遇见错误:Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityListene
- java.lang.ClassNotFoundException: javax.persistence.EntityListeners
- spring 整合hibernate Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity