• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

relationships using composite keys

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two beans (A and B) and their associated tables are defined as:
[table A]
name varchar
id integer
other columns...
primarykey is (name, id) which is defined as APK.class
[table B]
name varchar
id integer
bname varchar
other columns...
primarykey is (name, id, bname) which is defined as BPK.class
Question: How do I setup the relationship between A and B to perform
cascade delete (i.e. deleting A would automatically delete associated
B)? The database tables (oracle) are already setup to do cascade delete.
I've tried this but get an error when running appc (In relationship 'A-
B', role 'B-Has-One-A', a cmp-field used to implement this relationship
has a primitive type. All cmp-fields that double as cmr-fields must have
an object type.)
in ejb-jar.xml:
<relationships>
<ejb-relation>
<ejb-relation-name>A-B</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>A-Has-Many-B</ejb-relationship-role-name>
<multiplicity>one</multiplicity>
<relationship-role-source>
<ejb-name>AEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>brecs</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>B-Has-One-A</ejb-relationship-role-name>
<multiplicity>many</multiplicity>
<cascade-delete/>
<relationship-role-source>
<ejb-name>BEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>
in weblogic-ejb-jar.xml:
<weblogic-rdbms-relation>
<relation-name>A-B</relation-name>
<weblogic-relationship-role>
<relationship-role-name>B-Has-One-A</relationship-role-name>
<relationship-role-map>
<column-map>
<foreign-key-column>name</foreign-key-column>
<key-column>name</key-column>
</column-map>
<column-map>
<foreign-key-column>id</foreign-key-column>
<key-column>id</key-column>
</column-map>
</relationship-role-map>
<db-cascade-delete/>
</weblogic-relationship-role>
</weblogic-rdbms-relation>
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I would presume that doing findbyPrimaryKey(PKClass pk)
and then doing a remove() on the interface would do it?
Anyway I started using entity beans with CMP/CMR a few weeks ago. I would be interested in collaborating on this.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic