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