users@glassfish.java.net

GF-embedded not loading/recognizing class annotated with @PersistenceContext

From: <forums_at_java.net>
Date: Tue, 5 Jul 2011 12:17:38 -0500 (CDT)

Hi, I'm trying to run some unit tests by using glassfish-embedded-all
(v:3.1). Below is a description of my context.

======== CURRENT CONTEXT
=====================================================

I have the following projects, all managed with Maven.  
-------- DOMAIN PROJECT
------------------------------------------------------

Contains only @Entity annotated classes + META-INF/persistence.xml. This
project is bundled into a jar and installed in a local maven repository.

-------- COMMONS PROJECT
-----------------------------------------------------

Contains utility classes and classes included by other projects. This project
is also bundled into a jar and installed in a local maven repository.

-------- COMPONENT PROJECT
---------------------------------------------------

This project is the one I'm trying to test. It contains a class named
MyServiceImpl which is annotated with @LocalBean and @Session which exposes
some business methods. This same class has a reference to a DAO class
(annotated with @Inject) which is the one interfacing with JPA.  This
project has dependencies to /domain /and /commons/ meaning that they are
included in the classpath as jars.

*_at_Stateless @LocalBean* public class MyServiceImpl implements MyService{
*_at_Inject private OrderDAO orderDAO;* @Override public Order createOrder(Order
order){ return orderDAO.store(order); } }
In my JUnit test I'm initializing the EJBContainer like this:

@BeforeClass public static void setUpClass() throws Exception { Map<String,
Object> props = new HashMap<String, Object>();
props.put(EJBContainer.MODULES, new File("target/classes"));
props.put("org.glassfish.ejb.embedded.glassfish.installation.root",
"./src/test/glassfish"); container = EJBContainer.createEJBContainer(props);
myService = (MyService)
container.getContext().lookup("java:global/classes/MyServiceImpl"); }
Within ./src/test/glassfish I have domains/domain1/domain.xml which I have
extracted from glassfish-embedded-all.jar as I had to configure a datasource
to a local mysql instance.

======== PROBLEM
=============================================================

My problem is that in order to make this work I need to unpackage the
dependencies (domain.jar and commons.jar) into my target/classes folder,
otherwise my tests fail. Seems like none of GF scanners is able to detect
neither the META-INF/persistence.xml bundled in domain.jar nor a class named
AbstractDAO which is annotated with @PersistenceContext. 

I tried including both jars in target/classes since there is where I'm
pointing EJBContainer.MODULES property to but this does not work.

Does anybody know how to make embeddedGF to load and recognize the JEE
resources I have bundled into those dependencies?

Regards,

Sebastian


--
[Message sent by forum member 'sricaldoni']
View Post: http://forums.java.net/node/819009