13
votes

Is there a way to avoid recreating the connection pool to an in-memory database when reloading after a code change?

[info] - application - Shutting down connection pool.
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.db.DefaultDBApi - Database [default] connected at jdbc:h2:mem:play

Even if you modify something that's not related to the database, Play shuts down the connection pool and recreates it right after. There must be good reason, and if not, a workaround.

Any help appreciated.

1
I guess you use continous mode. Only way is to turn off this mode, because every time source file changes application is rebuilt and restarted.Zernike
@Zernike I believe OP is talking about Play's own continuous recompile, not sure if that's based off SBT's or completely different.Ryan
It,s based on sbt custom task.Zernike
@Thomas mailing list people keep pointing me towards using a @Singleton and injecting it... but I have not fully guiced my app yet.. I hope we can figure this out! Clearly it is possible because Netty stays up between compiles.bwawok
Is the shutting down of the connection pool the real problem? Is it possible that the problem is that you lose your test data and you have to start again? In that case this could help stackoverflow.com/questions/12292050/…Jonas Anso

1 Answers

0
votes

It's normal behavior of the development mode. I can only add that play reload code after request (if the code was changed). All application is reloaded, so connection pulls are recreated as well (and the in-memory database instance if it was created by play):

Running the server in development mode

If you want to persist the data in your in-memory database then you need to run it separately or use it with persistent ability:

How to use a persistent H2 database