Skip to content

H2EmbeddedDatabaseConfigurer should set DB_CLOSE_ON_EXIT=false [SPR-11573] #16197

@spring-projects-issues

Description

@spring-projects-issues

Torsten Krah opened SPR-11573 and commented

I've traced down a race condition after a few hours and found the fix. So I wonder if this can be included in the default configuration of the ConnectionProperties for H2EmbeddedDatabaseConfigurer.

Per default DB_CLOSE_ON_EXIT is true. Thus, if the test VM exits, the Spring ApplicationContext gets closed, but H2 also registers a shutdown hook: the DatabaseCloser thread shuts down the database in parallel. As a consequence, all scripts configured via <jdbc:script location="..." execution="DESTROY" /> (that should be run at closing time) fail because the database was already shutdown.

It would be good if the following line in H2EmbeddedDatabaseConfigurer.configureConnectionProperties() ...

properties.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", databaseName));

... could be modified as follows:

properties.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false", databaseName));

This would result in ...

<jdbc:script location="classpath:emptyTables.sql" execution="DESTROY" />

not emitting errors about missing tables.


Affects: 4.0.2

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions