File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB relation one:many ?? 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 » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB relation one:many ??" Watch "EJB relation one:many ??" New topic
Author

EJB relation one:many ??

Georg Joo
Ranch Hand

Joined: Feb 24, 2004
Posts: 49
Hi

I have a prblem to understand the EJB relations.
Example: the first table (invoice) has a key "Number" and the second table
(invoicepositions) has the key "Number, Posnumber".

The reltaion is 1:many unidirectional.

How have I to solve this situation ? Has Bean invoice a CMR field "Number" ? This field this a CMP field (!?). Have I tho declare a CMR field "positions"?
What's the right way to do this ?

Thanks

Georg


SCJP, SCWCD, SCBCD<br /> <br />Vienna, Austria
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Actually, in the Invoice bean class, you should declare the following method that represents the invoicePositions CMR field:
public abstract Collection getInvoicePositions();
The returned Collection will contain InvoicePositionLocal references.

And now, your deployment descriptor should look like:

Note that you can freely change the content of ejb-relation-name, ejb-relationship-role-name.

I hope this helps


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Georg Joo
Ranch Hand

Joined: Feb 24, 2004
Posts: 49
Yes, this was the answer I need.

Thanks

Georg
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
And depending on your application server you still have to write the vendor-specific deployment descriptor for mapping the CMR fields to the proper columns in your database.

Or you use XDoclet and you write everything in the source file
[ July 28, 2004: Message edited by: Valentin Crettaz ]
Georg Joo
Ranch Hand

Joined: Feb 24, 2004
Posts: 49
Hi

Can I map the CMR Field getInvoicePositions() to a PrimaryKey field ?
I get always an error.
Is it possible to use Number of the PK for the CMR field ??? (If it is possible, then I have to read the jonas documentation twice).

Or have I to insert an own column for the CMR filed, that holds the same value as the Number of the PK (I thik not)???

Thanks

Georg
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB relation one:many ??
 
Similar Threads
Hibernate .hbm.xml - Referential Integrity constraint
CMR Problem
EJB and CMR questions
Can a CMR field be part of a compound primary key
CMR Problem