users@glassfish.java.net

Glassfish, Spring, EJB - EntityManagers

From: <glassfish_at_javadesktop.org>
Date: Tue, 07 Apr 2009 15:30:10 PDT

Hello,

I'm working on an application and trying to find a good way to integrate Spring into EJB3. My goal is to be able to inject an EntityManager into my Spring beans so that they can access entities and the database when needed. When running in Glassfish I would like my Spring beans to get a container managed EntityManager from Glassfish and when running in a testing capacity I'd like to be able to use an entity manager provided by Spring.

Glassfish doesn't seem publish the Persistence Unit to JNDI (unless I do something like this in my EJB which makes it available for the session:

[i]@PersistenceContext(name = "persistence/em")
private EntityManager em;[/i]

So it doesn't seem like I can just simply lookup the Glassfish managed EntityManager from JNDI in my Spring configuration - or am I wrong?

Ultimately I'd like to be able to use Spring's JpaTemplate inside my Spring beans but I'd still like to get the EntityManager from Glassfish if possible.

Any ideas? Anybody using Glassfish with Spring, JPA and EJB3?
[Message sent by forum member 'euqaz' (euqaz)]

http://forums.java.net/jive/thread.jspa?messageID=341066