playframework/play1 — pull request #804 by angryziber (2014-10-03 20:38:58+00:00)
Title: Prevent DB connection leaks in Play 1.3.x

Play 1.2 used to fail in case you use @NoTransacction and try to read from the DB (e.g. User.findById())

Play 1.3.x for some reason currently creates a new EntityManager in case transaction is not active, which is never closed, resulting in connection leaks in the pool.

This patch reverts the behaviour to the old one, which is much safer.
We have been running Play 1.3.x on production for some time and discovered connection leaks (exhausted connection pool) after some time.

This pull request fixes the issue - bugs in code, trying to read from DB outside of the transacction, will now fail as before and, most importantly, will keep connection pool in a normal state.

Please review commits separately - they also fix code duplication and other issues in JPA class, introduced in Play 1.3.x branch, so that it will be easier to spot other bugs there.