1. 程式人生 > >解決org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from2 to 0

解決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.

    

   注意:在寫或者修改javabean時能用快捷鍵就用快捷鍵