It's not a secret anymore!*
The moose likes BEA/Weblogic and the fly likes CMP maping - one to many unidirection in  wl7.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "CMP maping - one to many unidirection in  wl7.0" Watch "CMP maping - one to many unidirection in  wl7.0" New topic
Author

CMP maping - one to many unidirection in wl7.0

Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I like to do the following:
1) Map one bean corresponding to table A to many beans corresponding to table B
2) table B has two columns as the primary keys.
3) One of the primary key column in table B is a foreign key pointing to the primary key of table A.
I am not able to map this scenario. I guess the mapping is possible as long as each table has its own unrelated primary keys. If anyone has tried this, please...please...help.
Thanks.
sameerleekha
Greenhorn

Joined: Jan 22, 2002
Posts: 26
Hi,
You can use the following code for providing the mapping of Bean corresponding to table A with Beans corresponding to table B
<relationships>
<ejb-relation>
<ejb-relation-name>BeanA_with_BeanB1</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>XXXXXXXXXXXXX</ejb-relationship-role-name>
<multiplicity>one</multiplicity>
<relationship-role-source>
<ejb-name>BEANA</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>YYYYYYYYYYYY</ejb-relationship-role-name>
<multiplicity>many</multiplicity>
<relationship-role-source>
<ejb-name>BeanB1</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
<ejb-relation-name>BeanA_with_BeanB2</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>XXXXXXXXXXXXX</ejb-relationship-role-name>
<multiplicity>one</multiplicity>
<relationship-role-source>
<ejb-name>BEANA</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>YYYYYYYYYYYY</ejb-relationship-role-name>
<multiplicity>many</multiplicity>
<relationship-role-source>
<ejb-name>BeanB2</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>


sameer
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I am not sure why you would need to define two <ejb-relation> elements. For examples, I have one Customer bean related to many Address beans. In ejb-jar.xml, I have defined <ejb-relation> element as follows:

Now I like to know how you define the above relationship in weblogic-cmp-rdbms-jar.xml. The table for CustomerBean is CUSTOMER with CUSTOMER_ID as the primary key. The table for AddressBean is ADDRESS with CUSTOMER_ID and ADDRESS_TYPE as compound primary keys.
I hope I explained my problem clearly. Please help. Thanks.
sameerleekha
Greenhorn

Joined: Jan 22, 2002
Posts: 26
hi,
I think u are thinking the simple prob. in a complex way.
Just define the maping for both the beans with their corresponding tables in a simple way as the mapping between the database field and the bean field.
Just inclue the foreigh key also like the other column feilds with the mapping between the foreign field name and the columm field name.
hope the above will help...
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Sameer,
I hope it is that simple. May be I didn't understand your sample ejb-jar.xml. I can map the Customer bean to customer table and Address bean to Address table. That is not the issue here. I like to use CMR to take advantage of,
1) cascade delete
2) automatic update of Address table by adding and removing the Collection objects in Customer bean.
Thanks again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CMP maping - one to many unidirection in wl7.0
 
Similar Threads
Hibernate many-to-one composite key as foreign key
One-to-Many in a class having composite primary key
How to implement OneToOne entity without explicit id field
adding to a table with no primary keys
Compound map doubt