hibernate - SEVERE: Attempt to modify an identity column 'UID' -
I am using hibernate and I want to consistently add a new row to the table in my database.
I am using code in my action class:
try {session session = HibernateUtil. GetSessionFactory () getCurrentSession (); Session.beginTransaction (); U = new user (); 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); } Hold (exception e) {this.addActionError ("oh .. an error has arrived ...! Email address is already registered, try with your new email address."); Return error; } Session.getTransaction (). Commit (); Session.close (); } Hold (exception e) {this.addActionError ("oh an error has occurred ...!"); Return error; } The page sometimes shows an error with an external catch and sometimes even internal hold. The glassfish server is logged:
Warning: SQL error: -1, SQLState: 42Z23 Critical: Attempt to modify identity column 'UID' SEVERE: Do not synchronize database state with session Could og.hibernate.exception.SQLGrammarException: Can not be inserted: [Beans. User] .. by reason: java.sql.SQLSyntaxErrorException: an identification column 'UID' attempt to modify. My table is the primary user 'UID', which is generated automatically from Genesis 1. Many fields other than the above are derived from the gates but they are given the default value as the table property with the creation of the line, so I decided not to apply gates and setter for them. I did not use the gueststor and setter for 'UID' because it is automatically generated.
Can someone tell if error can be ...? thank you in advanced.
session.save (u); Do not always set fire to SQL immediately but share them if possible. It calls on transaction.commit or session.flush () .
Comments
Post a Comment