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.

Thomas
  • 1,491
  • 13
  • 23
  • I guess you use [continous mode](http://www.scala-sbt.org/0.13/docs/Triggered-Execution.html). Only way is to turn off this mode, because every time source file changes application is rebuilt and restarted. – Zernike Jul 19 '15 at 19:38
  • @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 Jul 20 '15 at 00:25
  • It,s based on sbt custom task. – Zernike Jul 20 '15 at 03:53
  • @Zernike I am not using sbt's triggered execution (using `run` instead of `~run`, see [this](https://playframework.com/documentation/2.4.x/PlayConsole#Running-the-server-in-development-mode) and [this](https://playframework.com/documentation/2.4.x/PlayConsole#Using-sbt-features)). Play's documentation says "Play will check your project and recompile required sources". Why is it required to recreate the connection pool? – Thomas Jul 21 '15 at 07:54
  • 1
    @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 Jul 21 '15 at 13:21
  • 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? – code4j Jan 20 '16 at 17:37
  • 2
    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 http://stackoverflow.com/questions/12292050/how-to-use-a-persistent-h2-database-in-the-play-framework-instead-of-in-memory – Jonas Anso Feb 17 '16 at 10:40

1 Answers1

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

Community
  • 1
  • 1
Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46