how to enable referential integrity in HSQL Db in-memory unit tests

戏子无情 提交于 2019-12-05 12:09:08

You can use: "SET DATABASE REFERENTIAL INTEGRITY FALSE" and "SET DATABASE REFERENTIAL INTEGRITY TRUE" sql statements

HSQLDB is very strict on referential integrity, unless it is turned off. JPA implementations actually use different strategies in this area for different databases. For example, with one database engine the implementation may define foreign keys with cascading deletes and delete the parent object, but for another engine it may delete the children of an object separately, before deleting the parent.

Therefore, HSQLDB as the development database helps you find the errors to a large extent, but you still need to validate your software by running against the target database.

Going back to the specific question, if you run one of your tests with a file database like this:

jdbc.url=jdbc:hsqldb:file:/home/db/SampleProject;hsqldb.write_delay=false;shutdown=true

You can then open the database with the DatabaseManager after the test and check the table and constraint definitions. If the JPA does create foreign keys, you can check for yourself that the contraints are enforced by HSQLDB if you try some inserts and deletes.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!