I have a Spring Boot application with mysql db, but when running tests HSQLDB is used. Is it possible to connect to this in-memory database to execute a query? What I have to change in tests/application to run it? I've already tried to run hsql database manager and connect to this database but it seems to be empty but actually it is not empty because in the application I'm debugging the code and read data from this database.
Asked
Active
Viewed 4,183 times
3
-
Are you using SpringDataJpaTest? – Simon Martinelli Aug 04 '20 at 06:58
-
I'm using Spring Data JPa but I'm not sure if I'm using SpringDataJpaTest... I have integration tests with spring context. – Maad Maad Aug 04 '20 at 07:24
-
And you do a commit? – Simon Martinelli Aug 04 '20 at 07:52
-
2This shouldn't have been closed. The question is clear to those who know about this setup and the answer is to run HSQLDB as a server serving the in-memory database. – fredt Aug 04 '20 at 19:27
1 Answers
3
You have two options.
One option is to start an HyperSQL (HSQLDB) Server in Spring. This option is discussed here in the answer How to start HSQLDB in server mode from Spring boot application You then start the HyperSQL DatabaseManagerSwing in a separate Java process and connect to the HyperSQL Server with the URL: jdbc:hsqldb:hsql://localhost/testdb
.
The alternative option is to start the HyperSQL DatabaseManagreSwing in Spring. You can modify the bean template given for the Server and start org.hsqldb.util.DatabaseManagerSwing
instead of the Server. In this case, the DatabaseManager should connect with the URL: jdbc:hsqldb:mem:testdb
.
Note in both cases, you need to specify the jdbc:hsqldb:mem:testdb
URL as the Spring data source.

fredt
- 24,044
- 3
- 40
- 61