users@glassfish.java.net

[Glassfish embedded] Problem with JPA2 entities in jar in a war

From: <glassfish_at_javadesktop.org>
Date: Mon, 06 Sep 2010 01:51:42 PDT

Hi everybody
We have used Glassfish Embedded for unittesting a project for a while now without any problems. The project is a single war with both EJB's and JPA2 entities.

Now we are trying to split up the application in different projects. We have put all the JPA2 entities together with persistence.xml in a separate maven jar project,
and the parent war project has a dependency to the jpa project. This works fine when deployed to Glassfish, but the TestNG tests using Glassfish Embedded stopped
working. No matter what we try, the persistence.xml doesn't seem to get loaded. This is the root exception we get:

...
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName evotePU
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:121)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:141)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:134)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:252)
        at no.evote.service.impl.BaseServiceImpl.create(BaseServiceImpl.java:53)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
        at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
        at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5243)
        at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
        at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:139)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
        at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
        at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5215)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:190)
        ... 32 more

We are using glassfish-embedded-all version 3.0, and the EJB embeddable API. This is how we start Glassfish:

        @BeforeSuite
        public void setUp() {
                Map<String, Object> properties = new HashMap<String, Object>();
                properties.put(EJBContainer.MODULES, new File("target/classes"));
                properties.put("org.glassfish.ejb.embedded.glassfish.instance.root", "./src/test/glassfish");
                container = EJBContainer.createEJBContainer(properties);
                context = container.getContext();
        }

This is in the war project, so target/classes refers to this project (with ejb's and controllers) and not the JPA2 project. I tried changing this to the JPA2 project, but it made no
difference.

Does anyone have any suggestions as to why this doesn't work? Having JPA2 entities in a jar as part of a war should work, right? All help appreciated!

Regards, Anders
[Message sent by forum member 'andersaab']

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