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

Posted 爱华顿g

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered fr相关的知识,希望对你有一定的参考价值。

 

错误信息

严重: 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.

    

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

以上是关于解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered fr的主要内容,如果未能解决你的问题,请参考以下文章

hibernate单独使用参考示例

hibernate 的OID

Hibernate的配置中,c3p0连接池相关配置

hibernate连接数据库的步骤

JPA的配置文件

如何强制初始化 Hibernate JPA 代理以在 JSON 调用中使用它