More Hibernate JPA troubles

When running JPA together with Grails (not tested on it’s own), with a Hibernate ORM either Hibernate, or with a pool the pool (c3p0), runs out of connections. The architecture of Reposita has a Grails frontend with a (Java) JPA backend to enable switching the frontend and backend independently. The MySQL database barks about to many connections. I do some persist() calls to the database, I guess around 50. Each call gets an EntityManager, does a transaction and closes the EM. Shouldn’t closing the EM close the connection and return it to the pool? Or is this a problem together with Grails, which also runs Hibernate to a MySQL database? Any ideas? I’ve run out of mine.

Update: I’m not sure what I’m doing wrong,

should work. But even when using with c3p0 as a pool, when calling this code several times, the connection count to the database increases until it reaches the limit, where the MySQL database barks about too many connections.

This might be caused by create-drop of my testing setup.

Update 2: As Dirk pointed out, of course em.close() should go into a finally block and I might add there should be some exception handling and rollback() action.

JPA hangs Grails, Part 2

As I wrote before, using Java JPA in my Grails application, the Grails application (0.6) hanged. After not much help from the mailing list, I updated to Grails RC1.0 without success. Adding the newest Hibernate JARs and Annotations JARs to the grails/lib directory solved my issue though. Grails no happily uses my JPA/Dao backend. Puh.

Grails, Hibernate and JPA: hanging application

When developing an application in Grails I’ve been adding a backend written for JPA. This should be no problem – you think. But while the unit test for the JPA backend work fine for themselves, when adding the backend to the Grails application, Grails hangs when accessing the EntityManager. It does not help that all my efforts to join the Grails mailing list with my gmail address have failed so far. I have no clue how to fix this problem which took most time out of my last weekend :-) Perhaps Hibernate does not like to act as a Grails ORM and at the same time as a JPA provider. Or I have JAR conflicts. Any ideas?

Update: It has been suggested that the problem might be that there are several incompatible ASM jars in the classpath.