personally i'd configure the EMF in spring simply getting the one of tomee using the same trick (but producing the EMF)
*Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/7/25 Chris Owens <[email protected]> > So... putting it all together, if I understand correctly (I am in part > writing this down because I suspect this thread will be useful to others). > Please correct where I have it wrong: > > 1) WEB-INF/resources.xml defines the datasources. > > 2) META-INF/persistence.xml defines a persistence unit making reference to > the datasources that were defined in resources.xml > > Those two alone are enough for OpenEJB to create an entitymanager, > transactionmanager, etc. Then... > > 3) META-INF/spring/applicationContext.xml contains the following, so that > Spring and OpenEJB see the same transaction manager: > > > 4) WEB-INF/web.xml contains a persistence-unit-ref that refers to the > persistence unit defined in persistence.xml (I have lost track of why I > need this at this point.) > > 5) Add class EmProducer as per your message. > > 6) within EJBs, when I want an Entity Manager, I just do > > > 7) Within Spring beans, when I want an Entity Manager, I do > > > I still have a problem. The Spring code is full of aspectj files > (generated > long ago by Spring Roo), each of which contains a @PersitenceContext > annotation and an EntityManager field. How, short of overriding Roo's > madness and editing them all by hand to replace that code with the > BeanProvider version, could I arrange things so that Spring injects the > right EntityManager? > > And finally, Spring complains if you don't configure an > EntityManagerFactory. I think I could do the same thing for an EMF that > you > do for an EM in your EMProducer example. Is there an obvious better way? > > > > > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Shared-Persistence-Context-between-Spring-Beans-and-EJBs-tp4664343p4664359.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
