[jboss-user] [EJB 3.0] - 4.2.2- Injection of PersistenceUnit in a different jar not w
jaikiran
do-not-reply at jboss.com
Tue Mar 11 03:38:05 EDT 2008
I am trying out a sample application on JBoss-4.2.2 with Java 1.5. I have a stateless session bean which expects an entitymanager to be injected:
package org.myapp.ejb.impl;
|
| import javax.ejb.Remote;
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import org.jboss.annotation.ejb.RemoteBinding;
| import org.myapp.ejb.AppManager;
|
| @Stateless
| @Remote ({AppManager.class})
| @RemoteBinding (jndiBinding = "AppManagerBean")
| public class AppManagerBean implements AppManager {
|
| @PersistenceContext (unitName="myapp_ejb3.jar#EJB3Persistence")
| private EntityManager em;
|
| public String getVersion() {
| System.out.println("EM is " + em);
| return "1.0";
| }
|
|
| }
|
The entitymanager is configured in a jar named myapp_ejb3.jar and the EJB is packaged in a jar named another_ejb3.jar. Both these jars are then packaged in a ear name EJB3Persistence.ear:
| EJB3Persistence.ear
| |
| |--- META-INF
| | |
| | |--- application.xml
| | |
| | |--- jboss-app.xml
| |
| |
| |--- another_ejb3.jar
| | |
| | |--- org.myapp.ejb.impl.AppManagerBean
| |
| |
| |--- myapp_ejb3.jar
| | |
| | |--- META-INF
| | | |
| | | |--- persistence.xml
|
|
|
The contents of application.xml is:
| <?xml version="1.0" encoding="UTF-8"?>
|
| <application>
| <display-name>MyEJB3</display-name>
|
| <module>
| <ejb>myapp_ejb3.jar</ejb>
| </module>
|
|
| <module>
| <ejb>another_ejb3.jar</ejb>
| </module>
|
|
| </application>
The contents of persistence.xml:
| <persistence>
| <persistence-unit name="EJB3Persistence">
| <jta-data-source>java:/EJB3PersistenceDS</jta-data-source>
| <class>blah.blah.blah</class>
|
| </persistence-unit>
| </persistence>
Now when i deploy this ear file, i get a deployment exception saying that the persistenceunit EJB3Persistence is not installed and hence the bean cannot be deployed:
| 12:41:59,332 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
|
| --- MBeans waiting for other MBeans ---
| ObjectName: jboss.j2ee:ear=EJB3Persistence.ear,jar=another_ejb3.jar,name=AppManagerBean,service=EJB3
| State: NOTYETINSTALLED
| I Depend On:
| persistence.units:jar=pp_ejb3.jar,unitName=EJB3Persistence
|
| --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
| ObjectName: persistence.units:jar=pp_ejb3.jar,unitName=EJB3Persistence
| State: NOTYETINSTALLED
| Depends On Me:
| jboss.j2ee:ear=EJB3Persistence.ear,jar=another_ejb3.jar,name=AppManagerBean,service=EJB3
A bit of debugging led me to the DeploymentPersistenceUnitResolver class which has this getPersistenceUnitDeployment(String unitName) method. This internally calls the findRelativeDeployment(String relativeName) method on JmxDeploymentScopeImpl which has this piece of code:
public Ejb3Deployment findRelativeDeployment(String relativeName)
| {
| String relativeShortName = relativeName.substring(3);
| return deployments.get(relativeShortName);
| }
|
The relativeName parameter that's been passed, has the value "myapp_ejb3.jar". However the substring(3) (not sure why this is being done) incorrectly changes this to "pp_ejb3.jar" and then uses this to look in the deployments map. As a result this always returns null which effectively means that the PersistenceUnit named myapp_ejb3.jar#EJB3Persistence could not be found.
To get around this, i changed the findRelativeDeployment method to:
| public Ejb3Deployment findRelativeDeployment(String relativeName)
| {
|
| return deployments.get(relativeName);
| }
This worked and the entitymanager was successfully injected in the bean.
2008-03-11 13:03:33,208 DEBUG [org.jboss.ejb3.Ejb3Module] Starting jboss.j2ee:service=EJB3,module=another_ejb3.jar
| 2008-03-11 13:03:47,505 DEBUG [org.jboss.injection.PersistenceUnitHandler] ***** adding PU dependency from located persistence unit: persistence.units:ear=EJB3Persistence.ear,jar=myapp_ejb3.jar,unitName=EJB3Persistence
| .....
| 13:03:49,802 INFO [EJBContainer] STARTED EJB: org.myapp.ejb.impl.AppManagerBean ejbName: AppManagerBean
| 13:03:49,865 INFO [EARDeployer] Started J2EE application: file:/D:/JBoss-4.2.2/jboss-4.2.2.GA/server/jaikiran/deploy/EJB3Persistence.ear/
|
|
Has this been reported before? If not, should i report this in the JIRA?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4135532#4135532
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4135532
More information about the jboss-user
mailing list