Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in EJB2.0 CMR Deployment

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I m developing a sample EJB Application using EJB CMP2.0 with CMR. I have two beans CartMaster & cartDetail with 1-to-many CMR relatioship between them. My Descriptors files are:-

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

<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar >

<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>

<enterprise-beans>
<entity >
<description><![CDATA[Description for CartDetail]]></description>
<display-name>Name for CartDetail</display-name>
<ejb-name>CartDetail</ejb-name>
<home>econify.cartdetail.interfaces.CartDetailHome</home>
<remote>econify.cartdetail.interfaces.CartDetail</remote>
<local-home>econify.cartdetail.interfaces.CartDetailLocalHome</local-home>
<local>econify.cartdetail.interfaces.CartDetailLocal</local>

<ejb-class>econify.cartdetail.ejb.CartDetailCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>CartDetail</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>cartbeanid</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>cartbeandetailid</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>partid</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>quantity</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>unitprice</field-name>
</cmp-field>
<primkey-field>cartbeandetailid</primkey-field>
</entity>

<entity >
<description><![CDATA[Description for ent1]]></description>
<display-name>Name for ent1</display-name>

<ejb-name>CartMaster</ejb-name>

<home>econify.cartmaster.interfaces.CartMasterHome</home>
<remote>econify.cartmaster.interfaces.CartMaster</remote>
<local-home>econify.cartmaster.interfaces.CartMasterLocalHome</local-home>
<local>econify.cartmaster.interfaces.CartMasterLocal</local>

<ejb-class>econify.cartmaster.ejb.CartMasterCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>CartMaster</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>cartdate</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>cartbeanid</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>customerid</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>status</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>totalvalue</field-name>
</cmp-field>
<primkey-field>cartbeanid</primkey-field>

<query>
<description><![CDATA[]]></description>
<query-method>
<method-name>ejbSelectmaxcartid</method-name>
<method-params>
</method-params>
</query-method>
<ejb-ql><![CDATA[SELECT MAX(cms.cartbeanid) FROM CartMaster AS cms]]></ejb-ql>
</query>

</entity>
</enterprise-beans>

<!-- Relationships -->
<relationships >
<ejb-relation >
<ejb-relation-name>Parent-to-Children</ejb-relation-name>

<ejb-relationship-role >
<ejb-relationship-role-name>Child-has-one-parent</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>CartDetail</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>parent</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>Parent-has-many-Children</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>CartMaster</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>children</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>

</ejb-relation>
</relationships>

<assembly-descriptor >
</assembly-descriptor>

</ejb-jar>
=========

jbosscmp-jdbc.xml:-
==========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

<jbosscmp-jdbc>
<defaults>
<datasource>java:/ProgressDS</datasource>
<datasource-mapping>PostgreSQL 8.0</datasource-mapping>
</defaults>

<enterprise-beans>
<entity>
<ejb-name>CartDetail</ejb-name>

<cmp-field>
<field-name>cartbeanid</field-name>
<column-name>cartid</column-name>

</cmp-field>
<cmp-field>
<field-name>cartbeandetailid</field-name>
<column-name>cartdetailid</column-name>

</cmp-field>
<cmp-field>
<field-name>partid</field-name>
<column-name>partid</column-name>

</cmp-field>
<cmp-field>
<field-name>quantity</field-name>
<column-name>quantity</column-name>

</cmp-field>
<cmp-field>
<field-name>unitprice</field-name>
<column-name>unitprice</column-name>
</cmp-field>
</entity>

<entity>
<ejb-name>CartMaster</ejb-name>

<cmp-field>
<field-name>cartdate</field-name>
<column-name>cartdate</column-name>

</cmp-field>
<cmp-field>
<field-name>cartbeanid</field-name>
<column-name>cartid</column-name>

</cmp-field>
<cmp-field>
<field-name>customerid</field-name>
<column-name>customerid</column-name>

</cmp-field>
<cmp-field>
<field-name>status</field-name>
<column-name>status</column-name>

</cmp-field>
<cmp-field>
<field-name>totalvalue</field-name>
<column-name>totalvalue</column-name>

</cmp-field>
</entity>

</enterprise-beans>

<relationships>
<ejb-relation>
<ejb-relation-name>Parent-to-Children</ejb-relation-name>

<ejb-relationship-role>
<ejb-relationship-role-name>Child-has-one-parent</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>cartid</field-name>
<column-name>cartid</column-name>
</key-field>
</key-fields>

</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Parent-has-many-Children</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</jbosscmp-jdbc>
===========

I am using JBOSS4.0 App server. When I m trying to deploy beans I get folowing error message:-
===========
11:35:08,125 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=ejb/CartDetail,service=EJB
org.jboss.deployment.DeploymentException: Role: Child-has-one-parent with multiplicity many using foreign-key mapping is not allowed to have key-fields
at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.loadKeyFields(JDBCRelationshipRoleMetaData.java:406)
at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.init(JDBCRelationshipRoleMetaData.java:184)
===========


Pls tell me where I m going wrong? I am trying this example since last 2 days but not successful yet.
Please help me.

Thanx a lot in advance.

Prash
 
Marco Antonio Reis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite simple, friend. Try adding this tag.

I hope its useful.


<relationships>
<ejb-relation>
<ejb-relation-name>Parent-to-Children</ejb-relation-name>
->>>> <foreign-key-mapping /> <<<<<-
<ejb-relationship-role>
<ejb-relationship-role-name>Child-has-one-parent</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>cartid</field-name>
<column-name>cartid</column-name>
</key-field>
</key-fields>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic