org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [实体类名]

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tianhongguo/article/details/83343636

在开发的时候用hibernate框架对两个实体建立了many-one的关系,通过id来查询数据不能查出来还报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [实体类名]

原因是建立关系的外键有空值,而且没有对映射文件中many-to-one设置not-found="ignore"导致,当然还有一种等效的注解方式,

在实体类的中的外键上添上 @NotFound(action=NotFoundAction.IGNORE)

猜你喜欢

转载自blog.csdn.net/tianhongguo/article/details/83343636
今日推荐