Hello everybody.
I am developping 2 ejb-jar modules (let's name them A and B for
readibility).
These ejb-jars will eventually reside in the WEB-INF/lib of a war
module, as
per the Collapsed EAR architecture.
Both ejb-jar files contains entities and stateless files. The
difference is
that A depends on B :
B defines a set of classes which are parent entities for some
classes in A.
Furthermore, A contains a stateless bean (MyManager) which requires
to be
injected whith the persistence unit.
In fact, MyManager acts as a manager for the entities in A.
At the war level, I define another persistence.xml in
WEB-INF/classes/META-INF :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence
"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>
<persistence-unit name="acme">
 
; <provider>org.hibernate.ejb.HibernatePersistence
<jta-data-source>commonsDatabase
<non-jta-data-
source>commonsDatabaseUnmanaged
<jar-file>../lib/A.jar
<jar-file>../lib/B.jar
<properties>
<property
name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5Dialect" />
<property
name="hibernate.hbm2ddl.auto" value="update" />
<property
name="hibernate.show_sql"
value="true" />
<property
name="hibernate.format_sql"
value="true" />
<property
name="hibernate.use_sql_comments" value="true" />
<property
name="hibernate.transaction.manager_lookup_class"
value="org.apache.openejb.hibernate.TransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>
At startup, the persistence unit loads just fine, every entity is
mapped and
some code I wrote at the war
level can successfully crud the entities in A or B.
But, since A and B does not contain any persistence.xml, the
injection of
the persistence unit in
MyManager fails. Here is what I get at startup :
INFO - openejb.home = D:\projets\CCV-Core\CCV-Core-TestMain
INFO - openejb.base = D:\projets\CCV-Core\CCV-Core-TestMain
INFO - Configuring Service(id=Default Security Service,
type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=commonsDatabase, type=Resource,
provider-id=Default JDBC Database)
INFO - Configuring Service(id=commonsDatabaseUnmanaged,
type=Resource,
provider-id=Default JDBC Database)
INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory,
type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
INFO - Found EjbModule in classpath:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\A.jar
INFO - Found EjbModule in classpath:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\classes
INFO - Found EjbModule in classpath:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\B.jar
INFO - AntiJarLocking enabled. Using URL cache dir
D:\projets\CCV-Core\CCV-Core-TestMain\temp
INFO - Configuring app:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\A.jar
INFO - Auto-deploying ejb MyManagerImpl:
EjbDeployment(deployment-id=MyManagerImpl)
INFO - Configuring Service(id=Default Stateless Container,
type=Container,
provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean MyManagerImpl:
Container(type=STATELESS, id=Default Stateless Container)
ERROR - FAIL ... MyManagerImpl: A persistence unit must be defined via
META-INF/persistence.xml to
satisfy @PersistenceContext ref "_em" to unit "". An example of a
suitable
persistence.xml might
be:name="">java:openejb/Resource/myDataSourcejava:openejb/Resource/
myUnmanagedDataSourcevalue="buildSchema(ForeignKeys=true)"/>
ERROR - Invalid
EjbModule(path=D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp
\WEB-INF\lib\A.jar)
WARN - Jar not loaded.
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\A.jar.
Module failed validation.
AppModule(path=D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp
\WEB-INF\lib\A.jar)
INFO - Configuring app:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\classes
INFO - Auto-deploying ejb MyTestBean:
EjbDeployment(deployment-id=MyTestBean)
INFO - Configuring PersistenceUnit(name=acme,
provider=org.hibernate.ejb.HibernatePersistence)
WARN - Unresolved ejb reference "test.beans.impl.MyTestBean/oneMgr"
in bean
"MyTestBean". Will attempt resolution again at runtime.
INFO - Loaded Module:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\classes
INFO - Configuring app:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\B.jar
INFO - Loaded Module:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\B.jar
INFO - Creating ProxyFactory(id=Default JDK 1.3 ProxyFactory)
INFO - Creating TransactionManager(id=Default Transaction Manager)
INFO - Creating SecurityService(id=Default Security Service)
INFO - Creating Resource(id=commonsDatabase)
INFO - Creating Resource(id=commonsDatabaseUnmanaged)
INFO - Creating Container(id=Default Stateless Container)
INFO - Assembling app:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\classes
INFO - PersistenceUnit(name=acme,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Hibernate EntityManager 3.2.1.GA
INFO - Hibernate Annotations 3.2.1.GA
INFO - Hibernate 3.2.5
INFO - hibernate.properties not found
INFO - Bytecode provider name : cglib
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - Processing PersistenceUnitInfo [
name: acme
...]
<< I cut some hibernate crap here >>
INFO - schema update complete
INFO - Jndi(name=MyTestBeanLocal) --> Ejb(deployment-id=MyTestBean)
INFO - Created Ejb(deployment-id=MyTestBean, ejb-name=MyTestBean,
container=Default Stateless Container)
INFO - Deployed
Application(path=D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp
\WEB-INF\classes)
INFO - Assembling app:
D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp\WEB-INF\lib\B.jar
INFO - Deployed
Application(path=D:\projets\CCV-Core\CCV-Core-TestMain\target\WarApp
\WEB-INF\lib\B.jar)
I understand that openEJB :
- loads A and its session beans, found MyManager which has this :
@PersistenceContext (name="acme") EntityManager em
- cannot find a persistence unit named ACME, hence discard MyManager
and A
alltogether.
- loads my war and creates a persistence unit named ACME in the
process
(there is a warning, since a bean in the war classes has a @EJB
MyManager oneMgr in it...)
- loads B gracefully
Well...
How can I make it possible for A to gain access to the exact same
instance
of acme persistence unit that is created later on ???
I'm a beginner in developping EJBs, so I hope that you are not
smiling and
thinking "young padawan, you need more basic training" :-D
Seriously, I really tried hard, crawled throuh the JSR 220 for the
past few
days w/o reading anything that
rang a bell for me. So any help would be appreciated.
Bye everyone and have fun with OpenEJB !!!!
--
View this message in context:
http://www.nabble.com/Sharing-persistence-unit-among-several-ejb-jars-in-a-collapsed-EAR-tp17628307p17628307.html
Sent from the OpenEJB User mailing list archive at Nabble.com.