Appfuse exception: No natively generated identity value

Source: Internet
Author: User

After a long time, I finally found a good solution on the Internet to solve the following problems. Thank you very much ....

 

 

Http://blog.sina.com.cn/s/blog_5da3d5c50100bjga.html

 

 

Appfuse exception: No natively generated identity Val

(15:43:12)

Reprinted
Appfusehibernatemysql Miscellaneous Category: hibernate
Appfuse hibernte MySQL is used together. When adding user data, the following exception occurs:

The database returned no natively generated identity value; Nested exception is org. hibernate. hibernateexception: the database returned no natively generated identity value

In Class 1, the primary key configuration is

@ ID @ generatedvalue (Strategy = generationtype. Auto)
Public long GETID (){
Return this. ID;
}

2. Set the database:

Mysql> describe app_user;

+ --------------------- + -------------- + ------ + ----- + --------- + ---------------- +
| FIELD | type | null | key | default | extra |
+ --------------------- + -------------- + ------ + ----- + --------- + ---------------- +
| ID | bigint (20) | no | pri | null | auto_increment |
| Account_expired | bit (1) | no | null |
| Account_locked | bit (1) | no | null |
| Address | varchar (150) | Yes | null |
| City | varchar (50) | no | null |
| Country | varchar (100) | Yes | null |
| Postal_code | varchar (15) | no | null |
| Province | varchar (100) | Yes | null |
| Credentials_expired | bit (1) | no | null |
| Email | varchar (255) | no | uni | null |
| Account_enabled | bit (1) | Yes | null |
| First_name | varchar (50) | no | null |
| Last_name | varchar (50) | no | null |
| Password | varchar (255) | no | null |
| Password_hint | varchar (255) | Yes | null |
| Phone_number | varchar (255) | Yes | null |
| Username | varchar (50) | no | uni | null |
| Version | int (11) | Yes | null |
| Website | varchar (255) | Yes | null |
+ --------------------- + -------------- + ------ + ----- + --------- + ---------------- +
The primary key is automatically increasing. However, this exception occurs when data is added:

The database returned no natively generated identity value; Nested exception is org. hibernate. hibernateexception: the database returned no natively generated identity value

 
3 JPA provides four standard usage methods: Table, sequence, identity, and auto.

Table: Use a specific database table to save the primary key.

Sequence: generate a primary key based on the sequence of the underlying database, provided that the database supports the sequence.

Identity: The primary key is automatically generated by the database (mainly the auto-growth type)

Auto: The primary key is controlled by the program.

4. Change the primary key:
 
@ ID @ generatedvalue (Strategy = generationtype. Identity)

The same error is found.

5. Execute the following statement in the database:
Alter table app_user auto_increment = 100;

All of a sudden.

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.