identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7
来源:互联网 发布:python 2.x.msi 编辑:程序博客网 时间:2024/05/21 08:54
1、错误描述
Exception in thread "main" org.hibernate.HibernateException: identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7at org.hibernate.event.internal.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)at org.hibernate.event.internal.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:194)at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:156)at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:225)at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214)at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403)at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)at com.you.hibernate.dao.StudentDao.saveStuInfo(StudentDao.java:73)at com.you.hibernate.dao.StudentDao.main(StudentDao.java:107)
2、错误原因
利用Hibernate批量添加,传入实体类参数,这里是用for循环进行批量添加;每循环一次,需要重新实例化实体类,但是却将实体类实例化放在循环外面
public static void main(String[] args) { TStudentInfo student = new TStudentInfo();for(int i=10001;i<=100000;i++){student.setId(i);student.setStuNo(i);student.setStuName("胡思思"+i);student.setStuAge(20);if(i%2==1){student.setStuSex("女");}else{student.setStuSex("男");}student.setStuQq(""+i+"45744");student.setStuAddr("湖南省长沙市");saveStuInfo(student);}}
3、解决办法
public static void main(String[] args) {for(int i=10001;i<=100000;i++){TStudentInfo student = new TStudentInfo();student.setId(i);student.setStuNo(i);student.setStuName("胡思思"+i);student.setStuAge(20);if(i%2==1){student.setStuSex("女");}else{student.setStuSex("男");}student.setStuQq(""+i+"45744");student.setStuAddr("湖南省长沙市");saveStuInfo(student);}}
1 0
- identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7
- identifier of an instance of com.jh.oa.bpm.model.JhBpmFormdata was altered from 266 to 267
- 缓存identifier of an instance of com.topsec.tss.web.model.event.Event was altered from … to …
- identifier of an instance of was altered from to null
- identifier of an instance of was altered from to null
- Hibernate学习: 异常 identifier of an instance of com.zhssh.vo.TUser was altered from 1 to 1
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- identifier of an instance ...... altered from ** to **
- 关于identifier of an instance of Object was altered from 6 to 6异常解决问题
- EJB3 Exception:identifier of an instance of net.model.entity.Role was altered from 2 to 0
- identifier of an instance of XXX was altered from 75
- 遇到错误 org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X 将int
- 异常:identifier of an instance of cn.ebank.pojo.News was altered from 2 to 2;
- merge对比引发的identifier of an instance of entity was altered from .. to ..报错
- identifier of an instance of .. altered to null ---- hibernate exception
- identifier of an instance was altered from XXXX to XXXX解决
- Android 缓存机制(一)
- bzoj3529: [Sdoi2014]数表
- [LeetCode]Keyboard Row - Python
- 发的好地方根据您发的
- 面向对象思想
- identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7
- 进程间通信——共享内存
- 开放才能进步!Angular和Wijmo一起走过的日子
- socket自定义数据格式转化二进制
- 二分查找
- HDU1023_Train Problem II_卡特兰数
- 解决AndroidStudio添加ProjectLibary后在编译时遇到的各种问题之解决方式索引(finished with non-zero exit value and so on...)
- 关于开发项目遇到的问题和错误
- IntelliJ Idea 常用快捷键列表