Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

spring-projects-issues opened this issue Mar 18, 2014 · 1 comment
in: data type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

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

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

Sam Brannen commented

Resolved as described in the comments for GitHub commit 8aefcb9:

Set DB_CLOSE_ON_EXIT=false in H2EmbeddedDbConfig

This commit sets the DB_CLOSE_ON_EXIT flag to false for embedded H2
databases loaded using H2EmbeddedDatabaseConfigurer (i.e., via Spring's
<jdbc:embedded-database /> XML namespace, EmbeddedDatabaseBuilder,
EmbeddedDatabaseFactory, and EmbeddedDatabaseFactoryBean).

@spring-projects-issues spring-projects-issues added in: data type: enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: data type: enhancement
None yet

No branches or pull requests

2 participants