Primary key generation problem in mysql-MySQL in hibernate

Source: Internet
Author: User
I recently used Mysql to connect to hibernate, and the generation policy is "identity". I encountered problems when adding data, such as adding a reimbursement form table and a reimbursement schedule (the relationship between the reimbursement form and reimbursement details is one-to-many, cascade & quot; all & quot;) is set in the reimbursement form. each time the data of the report object is saved, you will find that the reimbursement details in the last saved reimbursement form are saved to the object of this saved reimbursement form. After debugging, it is found that every time the program automatically sends the id of the report object to the ID value of the last inserted, and then the id is + 1 when the database is actually inserted, the reimbursement details object then changes the last foreign key value id to id + 1. what is the solution? Whether the primary key is mysqlhibernate database

I recently used Mysql to connect to hibernate, and the generation policy is "identity". I encountered problems when adding data, such as adding a reimbursement form table and a reimbursement schedule (the relationship between the reimbursement form and reimbursement details is one-to-many, cascade = "all") is set in the reimbursement form. each time you save the data of the report object, you will find that the reimbursement details in the last saved report are saved to the saved Report object.
After debugging, it is found that every time the program automatically sends the id of the report object to the ID value of the last inserted, and then the id is + 1 when the database is actually inserted, the reimbursement details object then changes the last foreign key value id to id + 1. what is the solution? Is it the relationship between the primary key generation policy, or do I need to manually add the primary key using assing?

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.