Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

DPP Patrick

Greenhorn
+ Follow
since Oct 05, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by DPP Patrick

First of all, thanks a lot.
Following your example:

User <-1----N-> Address
id user_id
UserEJB.java:
/**
* @ejb.interface-method
* @ejb.transaction type="Supports"
* @ejb.relation
* name="User-Address"
* role-name="User-has-many-Addresses"
* cascade-delete="no"
*/
public abstract Collection getAddresses ( ) ;
public abstract void setAddresses ( Collection addresses ) ;

AddressEJB.java:
/**
* @ejb.interface-method
* view-type="local"
* @ejb.transaction type="Supports"
* @ejb.relation
* name="User-Address"
* role-name="Addresses-have-a-User"
* cascade-delete="yes"
* @weblogic.column-map
* foreign-key-column="user_id"
* key-column="id"
*/
public abstract UserLocal getUser ( ) ;
public abstract void setUser ( UserLocal user ) ;

it generated:

ejb-jar:
<ejb-relation >
<ejb-relation-name>User-Address</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>Addresses-have-a-User</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete/>
<relationship-role-source >
<ejb-name>Address</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>user</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>User-has-many-Addresses</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>User</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>addresses</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>

</ejb-relation>


jbosscmp-jdbc:

<ejb-relation>
<ejb-relation-name>User-Address</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>Addresses-have-a-User</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>User-has-many-Addresses</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>


When I deploy that I receive this message:
Atleast one role of a foreign-key mapped relationship must have key fields (or <primkey-field> is missing from ejb-jar.xml): ejb-relation-name=User-Address

Then in jbosscmp-jdbc I insert this:
..
<ejb-relationship-role-name>User-has-many-Addresses</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>user_id</field-name>
<column-name>id</column-name>
</key-field>
</key-fields>
..

And I receive this:

Role 'User-has-many-Addresses' on Entity Bean 'User' : CMP field for key not found: field name='id'

Why isn't it finding the id?

Thanks all
Patrick
First of all, thanks a lot.

What book would you advice me to buy?
Dear John Todd, thanks for those links.
I've already read some chapters that book.

But my really problem is where I should write the xdoclet tags to make a relation among entity beans. For example:

In Table1Bean:

/**
* @ejb.relation name = "Table1-Table2"
* role-name = "Table1-do-table2"
*
* @jboss.relation related-pk-field = "tab1_id"
*
*/
public abstract java.util.Collection getTables2();
public abstract void settables2(java.util.Collection tables2);


In Table2Bean:

/**
* @ejb.relation name = "Table1-Table2"
* role-name = "Table2-da-Table1"
*
* @jboss.relation fk-column = "tab1_id"
*
*/
public abstract Table1 gettable1();
public abstract void setTable1(Table1 table1);

And the ejb-jar generated:
<ejb-relation-name>table1-table2</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>table2-da-table1</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>Table1</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>table2</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>table1-do-tables2</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Table2</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>table1</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>

But when I deploy I receive this message:

15:45:08,215 ERROR [EntityContainer] Starting failed jboss.j2ee:jndiName=Table1,service=EJB
org.jboss.deployment.DeploymentException: Role: Table1-da-Table2 with multiplicity many using foreign-key mapping is not allowed to have key-fields


What is it wrong in the relationship?

Thanks all

Patrick
I have already created my Entity Beans through Eclipse and Lomboz.
But I don't know how to specify my relationships.

Could somebody give me an example according my example tables?

Thanks all
Hi,

I've found some difficulties to relate that tables.
I'm working with eclipse, xdoclet, jboss.

Table1:
tab1_id - PK
tab1_nm
tab1_ds

Table2:
tab2_id - PK
tab1_id - FK
tab2_nm
tab2_ds

Table3:
tab3_id - PK
tab2_nm - FK
tab3_nm
tab3_ds

How can I do it? Where can I start from?

Thanks all
Patrick