org.hibernate.ObjectNotFoundException: No row with the given identifier exists
来源:互联网 发布:嵌入式软件开发课程 编辑:程序博客网 时间:2024/05/01 10:19
1、错误描述
Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.you.hibernate.model.TStudentInfo#1]at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:247)at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:171)at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:160)at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)at org.hibernate.engine.internal.StatefulPersistenceContext.unproxyAndReassociate(StatefulPersistenceContext.java:667)at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:90)at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:946)at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:925)at com.you.hibernate.dao.StudentDao.deleteStuInfo(StudentDao.java:116)at com.you.hibernate.dao.StudentDao.main(StudentDao.java:167)
2、错误原因
public static void deleteStuInfo(int id){Session session = HibernateSessionFactory.getSession();session.beginTransaction();TStudentInfo student = (TStudentInfo)session.load(TStudentInfo.class, id);session.delete(student);session.getTransaction().commit();System.out.println("删除成功!");}/** * 方法描述: * 创建作者:游海东 * 创建日期:2017-2-20 * 创建时间:下午5:20:14 * 方法名称:main * 方法类型:StudentDao * 返回类型:void * @param args */public static void main(String[] args) {int id = 1;deleteStuInfo(id);}
由于id=1的记录已经删除,再次调用删除方法,会报错
3、解决办法
(1)首先,在调用删除方法前需要按照ID进行查询一次
(2)然后,如果该ID的记录存在,才能调用删除方法
(3)最后,调用删除操作进行删除记录
0 0
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists .
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- rg.hibernate.ObjectNotFoundException: No row with the given identifier exists
- 【hibernate】错误org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- 【hibernate】关于org.hibernate.ObjectNotFoundException: No row with the given identifier exists 的快捷解决问题
- 【hibernate】org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
- 关于org.hibernate.ObjectNotFoundException: No row with the given identifier exists 的快捷解决问题
- 关于org.hibernate.ObjectNotFoundException: No row with the given identifier exists 的快捷解决问题
- 忽略org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- 关于org.hibernate.ObjectNotFoundException: No row with the given identifier exists 的快捷解决问题
- Linux 下Altera SPI驱动使用
- js 是否包含某个字符串,截取字符串
- 话说装潢
- bootstrap表单
- Android EditText inputType常用属性值含义
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- 【网络流24题-18】分配问题(BSOI2558)
- XPATH如何选择不包含某一个属性的节点?
- linux和unix的区别
- JAVA数据结构和算法(二)—线性查找
- RadioButton自定义背景图及字体颜色
- 使用HttpSessionListener接口监听Session的创建和失效
- 树莓派教程1-初次见面
- Android应用Design Support Library完全使用实例