1. 程式人生 > >org hibernate id IdentifierGenerationException錯誤解決方法

org hibernate id IdentifierGenerationException錯誤解決方法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():

ID主鍵生成策略為assigned 由應用程式負責生成主鍵識別符號

<id name="id" type="java.lang.String">    <column name="ID" length="32" />    <generator class="assigned" /></id>
而在儲存時沒有設定ID

session.save(entity);

導致出現此錯誤


解決方法:

1、在儲存時手動設定個ID即可:

entity.setId(UUID.randomUUID().toString());session.save(entity);

2、修改主鍵生成策略為其他


作者:itmyhome



           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述