When everything is normal at the end of entity, the unit test still encountered the following problems:
Oracle. toplink. Essentials. Exceptions. databaseexception internal exception: COM. MySQL. JDBC. Exceptions. jdbc4.mysqlintegrityconstraintviolationexception: duplicate entry '0' for key'primary '.
Check whether the primary key generation policy is @ generatedvalue (Strategy = generationtype. Identity.
My problem is solved in the database: in the database, the primary key is not set to auto growth. Set the primary key of an existing table to auto-increment. The SQL statement is:
Alter table course change course_id int (10) Not null auto_increment;
Hibernate annotation defines the default value of a field
The default values of attributes defined in Java classes cannot be directly mapped to database definitions.
For example, private string a = "";
Public String geta (){};
The database Field A does not have default.
You can use columndefinition in annotations column to solve this problem.
@ Column (columndefinition = "varchar2 (2) default '11 '")
Public String geta (){};
The field can have the default value.
Note that the field type must be specified, because hibernate will write the columndefinition content directly in the DDL of the generated object, so the syntax must be correct.