Play 2.4 - How to avoid recreating the database pool connection after a code change?
Asked Answered
A

1

13

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.

Anselme answered 19/7, 2015 at 19:22 Comment(7)
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.Blab
@Blab I believe OP is talking about Play's own continuous recompile, not sure if that's based off SBT's or completely different.Maraschino
It,s based on sbt custom task.Blab
@Blab I am not using sbt's triggered execution (using run instead of ~run, see this and this). Play's documentation says "Play will check your project and recompile required sources". Why is it required to recreate the connection pool?Anselme
@Anselme 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.Charles
I have also faced the same problem, it takes quite a long time to review my change after my refresh on the browser. Did you find the solution?Onions
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 #12292550Arria
P
0

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

Presbyterate answered 13/2, 2017 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.