解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from2 to 0

错误信息

严重: Servlet.service() for servlet [springmvc] in context with path [/order] threw exception [Request processing failed; nested exception is 
org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from 6 to 0] with root cause
org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from 6 to 0
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:85)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
......

出现原因:

  1.出现这种错误一般都是因为映射文件中的字段类型和实体类中的元素类型不相同!

    eg.

    映射文件中id的类型是Integer,也就是int类型的,而实体类中id的类型是long,问题就出现在这里!

  2.javabean代码不标准(在写或者修改javabean时一些细节问题没有做好)

    eg.

    解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from2 to 0

   注意:在写或者修改javabean时能用快捷键就用快捷键

上一篇:identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from错误


下一篇:identifier of an instance of com.xxx.model.system.xxxObject was altered from 1765 to 1766