0
我正在使用hibernate。並且我想持久地在數據庫的表中添加一個新行。SEVERE:嘗試修改標識列'UID'
我用我的行動類的代碼是:
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
u = new Users();
u.setAge(this.getAge());
u.setCity(this.getCity());
u.setEmail(this.getEmail());
u.setName(this.getUsername());
u.setPassword(this.getPassword());
u.setSex(this.getSex());
try {
session.save(u);
}
catch (Exception e) {
this.addActionError("Oops. An Error Encountered...! Email address already registered. Try with your new email address.");
return ERROR;
}
session.getTransaction().commit();
session.close();
} catch (Exception e) {
this.addActionError("Oops. An Error Encountered...!");
return ERROR;
}
頁面顯示錯誤有時外鍵鎖,有時內抓住的。 GlassFish服務器日誌是:
WARNING: SQL Error: -1, SQLState: 42Z23
SEVERE: Attempt to modify an identity column 'UID'.
SEVERE: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [beans.Users]
..
Caused by: java.sql.SQLSyntaxErrorException: Attempt to modify an identity column 'UID'.
我的表是「用戶」具有主鍵「UID」,這是自動生成的增量加1。有比上述的getter檢索但這些是其他還許多領域給定默認值作爲創建行的表屬性,所以我決定不爲他們應用getter和setter。我也沒有使用'uid'的getter和setter,因爲它是自動生成的。
有人可以指出什麼可以是錯誤...? 在此先感謝。
發佈用戶映射,我懷疑有一個錯誤 – Firo 2012-07-12 08:57:51