Beginner Hibernate writes an entity class person and then intends to save the object into the database Javee with the Save () method of the Session object in the main () function. After running the console report Field ' id ' doesn ' t has a default value error prompt. Check the configuration file and the code of each class feel no problem, then run still error. The Person.hbm.xml mapping file that is written is shown below:
The primary key type gets specified as "native" by the database generation. Later, the check found that the person table already exists in the Java EE database, and that the ID default value in the table is 0, not the self-increment property. after deleting the person table, run hibernate program, run by Hibernate program to create person table. The test was successful. The <generator class></> property of the ID is "native" (the error is because the table person already exists in the specified database, and the ID property in the table is not self-increment by default.) Delete the table and run the program). or do not change the ID property of the table person, change the <generator class></> property of the ID in the mapping file to "assigned" (the type specified by yourself), or you can successfully implement the operation.