users@glassfish.java.net

Glassfish And Compass

From: <glassfish_at_javadesktop.org>
Date: Wed, 09 May 2007 23:36:23 PDT

Most of the projects based on Glassfish using compass have been using Spring as well. While there are many reasons to use Spring, it seems to be a bit redundant when considering Glassfish comes stock with many of the features and components that Spring offers.

The one problem I've had to deal with in getting Compass up and running is that you need to have a single instance of the compass device, in my case the SingleCompassGps and JpaGpsDevice. To get these objects properly initialized, you need an instance of the shared EntityManagerFactory, and *not* the wrapper that @PersistenceUnit delivers.

So far, I've just created a singleton that must be invoked from within a BMT stateless session bean. It's a bit of a hack, since I'm actually using the static resolver on EntityManagerFactoryWrapper to get the actual factory. I can't help but think that there's a better way to do handle the initialization, perhaps from a managed bean or management extension? I've looked over the documentation, and haven't found much to indicate either way. I have yet to actually inspect code. Can the same EntityManagerFactory used throughout JPA containers be derived in either an MBean or JMXcase?

I'm open to any suggestions? One caveat, however, you can't use Persistence.createEntityManager(...) as it will gen up a different instance of an EntityManagerFactory than that delivered to Container via injection, which will render the system useless.

If a Singleton object helper is the way to go, then I'll publish my code shortly. Otherwise, I'm all ears. This is one case where I somewhat miss JBoss, which featured (at least in previous releases) annotations for @Management classes, which IIRC, had access to container EMFs.

-jjk
[Message sent by forum member 'jklappenbach' (jklappenbach)]

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