hibernate開發常見的錯誤
Caused by: Java.sql.SQLException: Field ‘id’ doesn’t have a default value
如果主鍵的生成策略採取的是identity,而資料庫中表的主鍵不是自動生成機制,則報這樣的錯誤
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.itcast.hibernate717.helloworld.Person#1]
如果在hibernate中,有兩個物件,但是其ID值是相同的,這樣的情況在hibernate中是不允許出現 (在hibernate中,強調物件的唯一性)
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (test/orders
, CONSTRAINT FKC3DF62E58940CCE2
FOREIGN KEY (customer_id
) REFERENCES customer
(id
))
違反了主外來鍵約束的原則
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: cn.itcast.hibernate717.manytomany.Student