Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 and EJB 2.1 Integration

 
nir ghosh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am trying to use EJB3.0 Application call from EJB 2.1 Application with JBoss 4.2.3 with eclipse hellios EJB Project and JPA facets added.

I have generated entities from tables.

persistance.xml:


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">;
<persistence-unit name="mmsTxn" >
<jta-data-source>java:/XAOracleDS</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<class>com.orga.mms.prototype.entity.AgentEntity</class>
<class>com.orga.mms.prototype.entity.CustomerEntity</class>
<class>com.orga.mms.prototype.entity.SvaEntity</class>
<class>com.orga.mms.prototype.entity.SvaTransactionEntity</class>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<validation-mode>AUTO</validation-mode>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>

orm.xml:

<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0">
<entity class="com.orga.mms.prototype.entity.CustomerEntity">
<table />
<attributes>
<id name="CUS_ID" />
<basic name="cusName">
<column name="CUS_NAME" optional="true" />
</basic>
</attributes>
</entity>
<entity class="com.orga.mms.prototype.entity.AgentEntity">
<table />
<attributes>
<id name="AGENT_ID" />
<basic name="agentCode">
<column name="AGENT_CODE" optional="true" />
</basic>
</attributes>
</entity>
<!-- <entity class="com.orga.mms.prototype.entity.SvaEntity">
<table name="TEMP_SVA" />
<attributes>
<id name="SVA_ACCNT_ID" />
<basic name="parentId">
<column name="PARENT_ID" />
<temporal>INTEGER</temporal>
</basic>
<basic name="parentType">
<column name="PARENT_TYPE" optional="true" />
</basic>
<basic name="svaBalance">
<column name="SVA_BALANCE" optional="true" />
</basic>
<basic name="svaType">
<column name="SVA_TYPE" optional="true" />
</basic>
</attributes>
</entity>
<entity class="com.orga.mms.prototype.entity.SvaTransactionEntity">
<table name="TEMP_SVA_TRANSACTION" />
<attributes>
<id name="SVA_TRANS_ID" />
<basic name="transAmount">
<column name="TRANS_AMOUNT" />
<temporal>INTEGER</temporal>
</basic>
<basic name="transNomenclature">
<column name="TRANS_NOMENCLATURE" optional="true" />
</basic>
<basic name="transType">
<column name="TRANS_TYPE" optional="true" />
</basic>
<basic name="tempSva">
<column name="SVA_ACC_ID" optional="true" />
</basic>
</attributes>
</entity>-->
</entity-mappings>

ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"; version="3.0">
<display-name>
MMS_Prototype </display-name>
<enterprise-beans>
<session>
<ejb-name>MMSProtoSBean</ejb-name>
<business-remote>com.orga.mms.prototype.sessionbean.MMSProtoSBRemote</business-remote>
<ejb-class>com.orga.mms.prototype.sessionbean.MMSProtoSBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<persistence-context-ref>
<persistence-context-ref-name>entity-manager</persistence-context-ref-name>
<persistence-unit-name>mmsTxn</persistence-unit-name>
<persistence-context-type>Transaction</persistence-context-type>
<!-- <injection-target>
<injection-target-class>com.orga.mms.prototype.sessionbean.MMSProtoSBean</injection-target-class>
<injection-target-name>MMSEntityManager</injection-target-name>
</injection-target>-->
</persistence-context-ref>
</session>
</enterprise-beans>
</ejb-jar>

oracle-xa-ds.xml in jboss-4.2.3.GA\server\default\deploy:

<?xml version="1.0" encoding="UTF-8"?>

<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->

<datasources>
<xa-datasource>
<jndi-name>XAOracleDS</jndi-name>
<track-connection-by-tx/>
<isSameRM-override-value>true</isSameRM-override-value>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbcracle:thin:@kolpsora01:1521pscgold</xa-datasource-property>
<xa-datasource-property name="User">nghosh</xa-datasource-property>
<xa-datasource-property name="Password">nghosh1234</xa-datasource-property>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
<no-tx-separate-pools/>

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>Oracle10g</type-mapping>
</metadata>
</xa-datasource>

<mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
name="jboss.jca:service=OracleXAExceptionFormatter">
<depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
</mbean>

</datasources>

ojdbc14.jar in "jboss-4.2.3.GA\server\default\deploy".

I have put java jars and ejb ear in jboss-4.2.3.GA\server\default\deploy and restarted the server.

Application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd">;

<module>
<java>EJB3_0.jar</java>
</module>

<module>
<ejb>MMS_EJB2_1.jar</ejb>
</module>

</application>

Exception I am getting bellow:
ERROR [URLDeploymentScanner] Incomplete Deployment listing:

--- MBeans waiting for other MBeans ---
ObjectName: jboss.ejb:service=EJBTimerService,persistencePolicy=database
State: CONFIGURED
I Depend On:
jboss.jca:service=DataSourceBinding,name=oracle-xa-ds

ObjectName: persistence.units:unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3

ObjectName: jboss.j2ee:jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3
State: NOTYETINSTALLED
I Depend On:
persistence.units:unitName=mmsTxn

ObjectName: persistence.units:jar=MMS_Prototype.jar,unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:jar=MMS_Prototype.jar,name=MMSProtoSBean,service=EJB3

ObjectName: jboss.j2ee:jar=MMS_Prototype.jar,name=MMSProtoSBean,service=EJB3
State: NOTYETINSTALLED
I Depend On:
persistence.units:jar=MMS_Prototype.jar,unitName=mmsTxn

ObjectName: persistence.units:ear=mms_ear.ear,unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:ear=mms_ear.ear,jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3

ObjectName: jboss.j2ee:ear=mms_ear.ear,jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3
State: NOTYETINSTALLED
I Depend On:
persistence.units:ear=mms_ear.ear,unitName=mmsTxn

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: persistence.units:jar=MMS_Prototype.jar,unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:jar=MMS_Prototype.jar,name=MMSProtoSBean,service=EJB3

ObjectName: persistence.units:ear=mms_ear.ear,unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:ear=mms_ear.ear,jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3

ObjectName: jboss.jca:service=DataSourceBinding,name=oracle-xa-ds
State: NOTYETINSTALLED
Depends On Me:
jboss.ejb:service=EJBTimerService,persistencePolicy=database

ObjectName: persistence.units:unitName=mmsTxn
State: FAILED
Reason: javax.persistence.PersistenceException: [PersistenceUnit: mmsTxn] Error while reading JPA XML file: META-INF/orm.xml
I Depend On:
jboss.jca:service=DataSourceBinding,name=XAOracleDS
Depends On Me:
jboss.j2ee:jar=MMS_EJB2_1.jar,name=MMSProtoSBean,service=EJB3

I am trying to solve for last whole week but couldnt solve please solve the problem.
Mainly,Alternatively if I can get a working code for EJB2.1 session bean calling EJB 3.0 entity bean sample project to nirgh20012001@yahoo.co.in and gnirjhar@gmail.com then it would be great help.

Thanks
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, EJB2.1 and EJB3 are completely different specifications and may not be compatible with each other.
 
Jatin Sutaria
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhan Sundararajan Devaki wrote:I believe, EJB2.1 and EJB3 are completely different specifications and may not be compatible with each other.


I know am a bit late but still for others who wander over here...

J2EE 5 specification is backward compatible with Ejb 2.1 and as such you can have both defined within a single application.xml file.

~Jatin Sutaria
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic