Go: Workaround for FOREIGN KEY constraint violation when using Dbunit test

Source: Internet
Author: User

Dbunit is a junit extension-based database testing framework. It provides a number of classes that abstract and encapsulate database-related operations. It associates the data in the database table with an XML file, which means that it allows the data to be converted between the XML file and the database. Based on this design pattern Dbunit can back up the database into a temporary XML file before testing, then delete all the data in the database and then put the simulated data we have written into the database, and finally, after the test, delete the existing data before depositing the data back up, Go back to the pre-test state to achieve the goal of each unit test not affecting each other.

However, if a foreign key association exists between the data tables that are dbunit tested, DBUNIIT cannot know which table should be deleted before deleting or restoring it after a backup, so it is easy to report a mysqlintegrityconstraintviolationexception error.

Workaround: Dbuniit is a JDBC Connection object to get the connection, you can add sessionvariables=foreign_key_checks=0 on the URL to prohibit foreign key constraint checking.

Go: Workaround for FOREIGN KEY constraint violation when using Dbunit test

Related Article

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.