*
The moose likes JBoss/WildFly and the fly likes is there anything wrong here ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "is there anything wrong here ?" Watch "is there anything wrong here ?" New topic
Author

is there anything wrong here ?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Hey all.
I need your help please.
I have two CMP beans, PlayerBean and TeamBean.
the relationship is one to many and bidirectional.
TeamBean has a CMR field called plalyers and PlayerBean has a CMR field called team, and there
are a setter and getter methods for these fields in each bean.
the database schema for TeamBean is :
TEAM_NAME, TEAM_CITY
and the bean contains the following fields :
name, city
the database schema for Player bean is :
ID, FULLNAME, NAME // name is the name of the city
and the bean contained the following fields :
id, fullname, name
here is a snipet from jboss-jdbc.xml :

my questions are :
1. is the relationships element right ?
2. what is the value of <field-name> should be ?
id (which is the name of a field in PlayerBean class) or
ID (which is the name of the field in database schema) ?
3. what is the value of <column-name> should be ?
TEAM_NAME (which is the name of a field in Team database schema) or
NAME (which is the name of a field in Player database schema) or
name (which is the name of a field in PlayerBean class) ??
4. which sould has the <foreign-key-mapping> element , TeamBean or PlayerBean ?
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Please, this is my first week with JBoss.
neva elsaeed
Greenhorn

Joined: Aug 16, 2004
Posts: 13
In your ejb-jar.xml you should have something like:
-----------------------------------------------------

<ejb-relation >
<ejb-relation-name>Team-Player</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>Player-Belongs-To-Team</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>YourPlayerEJB</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>team</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>Team-Has-Players</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>YourTeamEJB</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>players</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>


And in your jbosscmp-jdbc.xml you should have:
-----------------------------------------------


<ejb-relation>
<ejb-relation-name>Team-Player</ejb-relation-name>

<ejb-relationship-role>
<ejb-relationship-role-name>Player-Belongs-To-Team</ejb-relationship-role-name>
<key-fields/>

</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Team-Has-Players</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name> <!--field name of primary key of Team table-->
<column-name>teamId</column-name> <!--field name of team id in Player table
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is there anything wrong here ?
 
Similar Threads
Confused a little, alot
My last piece of CMR puzzle
Confused, create this method ??
How to Rollback Transaction in EJB2.0?
relationships using composite keys