Duplicate entry '0' for key 'Primary '.

Source: Internet
Author: User

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.



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.