Hi David,

I think primary key for "StudentClassGrade" would be best modelled as
deferred key, if your clients do not use explicit knowledge of both "ssn"
and "name" in the same method. (for example in findByPrimaryKey(Object)).
You can specify the primary key type as java.lang.Object in the deployment
descriptor.

I am assuming that you are using CMP2.0 entity beans. In that case, the
primary keys at the persistent store will be updated whenever the
relationship between "Student" and "Class" is associated / dissociated by
the container.

You will find good description on primary keys in about to be published book
by Richard Monson Haefel (ed 1.3, O'Reilly)

Regards,
Hemant
www.pramati.com

----- Original Message -----
From: "David M. Karr" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 05, 2001 11:13 PM
Subject: Re: PK for entity which has refs to other entities?


>>>>> "Evan" == Evan Ireland <[EMAIL PROTECTED]> writes:

    Evan> "David M. Karr" wrote:
    >>
    >> In an experimental application I'm building, I have two entities,
named
    >> "Student" and "Class" (no name conflict, I use "ClassBean",
"ClassHome", etc.).
    >>
    >> I also have an entity named "StudentClassGrade".  This essentially
reflects a
    >> "valued association", referencing a Student and Class, and containing
a Grade
    >> value.
    >>
    >> My first question is, what should be the types of the "Student" and
"Class"
    >> references in "StudentClassGrade" be?  Should they be the remote
references, or
    >> the primary keys?  The primary keys of "Student" and "Class" are,
respectively,
    >> "String ssn" and "String name".
    >>
    >> Then, dependent on that, my PK class for "StudentClassGrade" will be
a compound
    >> key.  I'm fairly certain this should contain the two primary keys of
the
    >> associated Student and Class, but I'm not quite sure how this should
work.

    Evan> Yes that would be reasonable.

    Evan> Then you can add methods: findByStudent and findByClass to the
home interface
    Evan> of your 'relationship' entity. When you find an entity, call a
method
    Evan> getGrade() to fetch the grade.

These are clear, but there's lots of details that I think I'm supposed to be
covering, but I can't find enough reasonable documentation.

For instance, does it matter what the NAMES of the fields in the primary key
are?  I thought I'd read that they either have to, or should, be the names
of
the associated fields in the bean.

Another issue: what would "findByPrimaryKey" look like?

    >> I'm having a lot of trouble finding good documentation and examples
for this
    >> sort of thing.  I've found umpteen examples of trivial beans and PKs,
but
    >> nothing like this.  I was hoping the new "Professional EJB" book
would cover
    >> this well, but it doesn't.

Again, is there anything I can read that covers development of more than
completely trivial primary keys and finders?

--
===================================================================
David M. Karr          ; Best Consulting
[EMAIL PROTECTED]   ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to