-
1. Re: CMP-Relation (m-n)
nikolai Jun 20, 2003 4:08 AM (in response to helgi)The syntax is correct, it depends what you have specified
in the
ejb-jar.xml
or/and
jbossjdbc-cmp.xml (At the table definition)
the field-name for many-many relation has to be
same as primary key field-name from entity "customers"
(the CMP field "login" must be specified in "customers" entity bean as primary key)
+ don't forget to preserve same order of relation definition in ejb-jar.xml
hope it helps
send ejb-jar.xml definition for entity customers and relation -
2. Re: CMP-Relation (m-n)
helgi Jun 20, 2003 4:32 AM (in response to helgi)Thanks for your answer.
My ejb-jar.xml for customer looks like that:
<![CDATA[]]>
<ejb-name>Customer</ejb-name>
CustomerHome
Customer
<local-home>CustomerLocalHome</local-home>
CustomerLocal
<ejb-class>CustomerCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
false
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Customer</abstract-schema-name>
<cmp-field >
<![CDATA[]]>
<field-name>password</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>login</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>prename</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>name</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>boorowdbooks</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>signedBooks</field-name>
</cmp-field>
<primkey-field>login</primkey-field>
For the relations I have the following:
<ejb-relation >
<ejb-relation-name>Book-Customer</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>Book-AllSigners</ejb-relationship-role-name>
Many
<relationship-role-source >
<ejb-name>Book</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>signers</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>Customer-SignedBooks</ejb-relationship-role-name>
Many
<relationship-role-source >
<ejb-name>Kunde</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>signedBooks</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
Any Ideas? -
3. Re: CMP-Relation (m-n)
nikolai Jun 20, 2003 4:51 AM (in response to helgi)The first mistake is
<ejb-name>Book</ejb-name>
it should be
<ejb-name>Customer</ejb-name>
(since you are using "login" field of Customers in jbossjdbc-cmp.xml - the relation must be in same order)
I don't know what the Kunde stands for
(did I miss the point?)
also replce
<ejb-name>Kunde</ejb-name>
with
<ejb-name>Books</ejb-name>
(only if you are using "isbn" field of Books in jbossjdbc-cmp.xml, if not leave it as it is)
Hope it helps
lp
Nikola -
4. Re: CMP-Relation (m-n)
helgi Jun 20, 2003 5:23 AM (in response to helgi)Hi Nicolai,
sorry, Kunde is the german word for customer. I wrote the app with german words an translated the whole thing for the postings and missed that one.
Is it correct that the order of the <ejb-relationship-role>s in jbosscmp-jdbc has to be the same as the order in ejb-jar?
When I switch the <ejb-relationship-role >
-entries in ejb-jar.xml (now Customer comes first and afterwards the book) I get the error that the field for key "isbn" could not be found.
The next thing is that all my deployment-descriptors are generated by XDoclet. I hope that tool generates the files in correct order.
I have no idea whats the cause. I hope you do.
Thank you very much for your help!
helgi -
5. Re: CMP-Relation (m-n)
nikolai Jun 20, 2003 7:53 AM (in response to helgi)can you send me the generated XML files
(ejb-jar.xml, jbossjdbc-cmp.xml)
nikola@rs-pi.com
You were right about the orders of the <ejb-relationship-role>s
I think that XDoclet should do it right, but I write them by
hand. (Don't know much about XDoclet)
p.s. Leave it in german
lp
Nikola
this is my example
two entity beans cmpUsers and cmpFsItems
in many to many relation.
<display-name>File system items CMP Bean</display-name>
<ejb-name>cmpFsItems</ejb-name>
<local-home>com.rspi.pms.cmp.FsItemsHome</local-home>
com.rspi.pms.cmp.FsItems
<ejb-class>com.rspi.pms.cmp.FsItemsBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>fs_items</abstract-schema-name>
<cmp-field><field-name>fsItemId</field-name></cmp-field>
<cmp-field><field-name>name</field-name></cmp-field>
<!--this is optional if you need a reference to fsItems in EJBQL query-->
<cmr-field><field-name>favouritesUsers</field-name></cmr-field>
<primkey-field>fsItemId</primkey-field>
<display-name>Users Entity CMP Bean</display-name>
<ejb-name>cmpUsers</ejb-name>
<local-home>com.rspi.pms.cmp.UsersHome</local-home>
com.rspi.pms.cmp.Users
<ejb-class>com.rspi.pms.cmp.UsersBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>users</abstract-schema-name>
<cmp-field><field-name>userId</field-name></cmp-field>
<cmp-field><field-name>userName</field-name></cmp-field>
<!--this is optional if you need a reference to fsItems in EJBQL query-->
<cmr-field><field-name>userFavourites</field-name></cmr-field>
<primkey-field>userId</primkey-field>
<!-- (users - fs-items) = favourites many-many -->
<ejb-relation>
<ejb-relation-name>user_favourites</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>user-has-favourites</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>cmpUsers</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>userFavourites</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>favourites-has-users</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>cmpFsItems</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>favouritesUsers</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
---------------------------------------jbossjdbc-cmp.xml
<!-- (users - fs-items) = favourites many-many -->
<ejb-relation>
<ejb-relation-name>user_favourites</ejb-relation-name>
<relation-table-mapping>
<table-name>fs_items_favourites</table-name>
</relation-table-mapping>
<ejb-relationship-role>
<ejb-relationship-role-name>user-has-favourites</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>userId</field-name>
<column-name>user_id</column-name>
</key-field>
</key-fields>
<read-ahead>on-load</read-ahead>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>favourites-has-users</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>fsItemId</field-name>
<column-name>fs_item_id</column-name>
</key-field>
</key-fields>
<read-ahead>on-load</read-ahead>
</ejb-relationship-role>
</ejb-relation>