Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.xxx.xx.model.info.News#15] 全新时代

场景分析:

主表:新闻表(news),从表:新闻评论表(newsComment)(含有newsId),系统在删除新闻的时候,没有将从表中的该新闻关联的评论删除的话,程序在加载新闻评论列表页时,通过Hibernate延迟加载newsComment.news对象,发现无法找到,所以报如上异常信息。

解决:在service中事务管理,首先依据newsId查询评论表中记录,先删除评论,后删除新闻。完成数据库数据完整性。

原文地址:https://www.cnblogs.com/simpledev/p/2986588.html