Field ' id ' doesn ' t has a default value error resolution

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.