H2 version: 2.1.214

H2 Automatic Mixed Mode (AUTO_SERVER=TRUE appended to H2 connection string) doesn't work with current spring H2 embedded configuration in H2EmbeddedDatabaseConfigurer.

Error from application:

org.h2.jdbc.JdbcSQLFeatureNotSupportedException: Feature not supported: "AUTO_SERVER=TRUE && DB_CLOSE_ON_EXIT=FALSE" [50100-214]

Current code:

https://github.com/spring-projects/spring-framework/blob/7ace9aa42940b06e5829c043a7e0eed855ffd262/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java#L64

Proposed change:

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

Comment From: sbrannen

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

Comment From: sbrannen

H2 Automatic Mixed Mode (AUTO_SERVER=TRUE appended to H2 connection string) doesn't work with current spring H2 embedded configuration in H2EmbeddedDatabaseConfigurer.

Where does the AUTO_SERVER=TRUE configuration come from?

H2EmbeddedDatabaseConfigurer does not add that.

Are you perhaps referring to a custom version of H2EmbeddedDatabaseConfigurer from a different project?


In any case, H2EmbeddedDatabaseConfigurer is used to create an embedded in-memory H2 database; however, Automatic Mixed Mode "doesn't work with in-memory databases."

In light of that, I am closing this issue.

If you feel that you have discovered a bug within the Spring Framework, feel free to report back with additional information.

Comment From: knapu

For connection to H2 database in version 1.4 in mixed mode (AUTO_SERVER=TRUE) we use connection string as below:

jdbc:h2:/opt/nifi*

which clear suggest that we use H2 in mode: Embedded (local) connection link to doc: https://www.h2database.com/html/features.html#embedded_databases

not:

jdbc:h2:mem:

which is appropriate for In-memory database

If you are sure that H2EmbeddedDatabaseConfigurer.java is not responsible for Embedded (local) connection, could you help me and indicate which class is responsible for ?

in reference to your question:

Where does the AUTO_SERVER=TRUE configuration come from?

Apache Nifi configuration, has a part where additional attributes for H2 connection string are added. And till version 1.16.3 of Apache Nifi (which used H2 in version 1.4), we were able to run nifi with AUTO_SERVER=TRUE attribute for H2.

In newer version we are not able to do that. we receive error:

org.h2.jdbc.JdbcSQLFeatureNotSupportedException: Feature not supported: "AUTO_SERVER=TRUE && DB_CLOSE_ON_EXIT=FALSE" [50100-214]

I've verified all files inside Nifi application and most of libraries and I found that parameter DB_CLOSE_ON_EXIT=FALSE is set only in spring-jdbc-5.3.24.jar in class H2EmbeddedDatabaseConfigurer.

Comment From: sbrannen

If you are sure that H2EmbeddedDatabaseConfigurer.java is not responsible for Embedded (local) connection,

Yes, H2EmbeddedDatabaseConfigurer is responsible for configuring an in-memory H2 database.

could you help me and indicate which class is responsible for ?

I think your best option in this situation is to ask for assistance on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.