Ok, so a pure Servlet container. In that case you might take a look at the EntityManager-per-request pattern which I used in this sample:
https://github.com/struberg/lightweightEE The trick is that you create a @RequestScoped EntityManager via CDI. The life span is not as long as with the em-per-session or em-per-conversation but you also have _much_ less issues with it. Of course you need to em.merge the entity to reflect your state into the DB in the callback request. The master branch uses resource-local and there is also a JTA branch if you are running in an EE container. I would need to upgrade this to the latest DeltaSpike version, OWB, etc (lacking a bit time here). But in general it should work pretty fine. Here are probably the most important parts: https://github.com/struberg/lightweightEE/blob/master/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java https://github.com/struberg/lightweightEE/blob/master/backend/src/main/resources/persistence-CaroLine.properties (you can forget about the @TransactionAware EM, you just need the @Default one) If you like to configure your DB in another way like the default properties then you can simply provide an @Alternative PersistenceConfigurationProvider. LieGrue, strub > Am 17.04.2015 um 16:53 schrieb [email protected]: > > On 17/04/2015 15:35, Mark Struberg wrote: >> What container are you running on? > Tomcat 8. > >> And do you need JTA or ‚just‘ resource local transactions? > I do not use JTA. > I find all what I need with stuff like DS @Transactionnal annotation. > > Best regards, > > Ludovic > | > | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT. > | >
