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.