Hi Ali,
- Yes, if you have @Transactional on your action the flow starts from there to call multiple services or DAOs and everything is happening within that action, you don't need to worry about committing a transaction. @Transaction annotation will take care of that. You don't need to close the "em" too. You can use all the methods (like find) of "em" as usual.
- You just call "JPA.em()" to get the current em(), there will be one em bind to the current thread. (or if you have different persistent units, you call JPA.em(persistentUnit))
- If you want to use C3P0, you need to provide the Connection provide in persistence.xml (org.hibernate.connection.C3P0ConnectionProvider) and additional properties, this is nothing specific to Play! here, you can search JPA+C3P0 and have the correct configuration
- Play's JPA and JPAApi classes are good enough for most of the scenarios. You don't really need to create your own EMFactory unless you really need to. Try using JPA.em() or JPA.em(persistentUnit) in all the places
- "JPA.withTransaction()" wraps the block (or lambda) in a transaction. If you use @Transactional, you dont need to use this method. As @Transaction annotation is an action composition, you can use it only in controllers, in case if you need a new transaction somewhere else, you can make use of that method.
One more thing to remember in future, @Transactional is a thread bind, so it blocks your main(action) thread. You may need to avoid that by wrapping your calls in a Promise, but that is when you have a huge number of concurrent requests. You can search and read up on that.
Hope I helped a bit!
Thanks,
Raj.