Hi Edward & David

Thanks for your replies. Now my understading is that you CANNOT use a CMR
field a part of a primary key. It may not be directly against the EJB 2.0
specs, however, it specifies that the "Primary Key may only be set once in
ejbCreate(...)" So any any attempt set the PK or any part of the PK outside
ejbCreate(...) throws an exception.

I had thought what exactly David has suggested. When I tried a similar
example, JBoss threw an exception when I tried to set the CMR field in
ejbPostCreate(...). In David's example, an exception would be thrown in
AddressEJB at:

  public void ejbPostCreate ( UserLocal user, Integer typeCode, ... )
  {
    setUser(user);
  }

So in conlcusion, I think, a CMR filed cannot be used as a PK.

Thanks & Best Regards
Mohammed



Message: 4
Date: Thu, 19 Feb 2004 09:55:28 -0800 (PST)
From: ed banfa <[EMAIL PROTECTED]>
Subject: Re: [Xdoclet-user] CMR & Primary Key
To: [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]

--0-1454298994-1077213328=:2225
Content-Type: text/plain; charset=us-ascii

Hi
I not am yet complete on ejb but I dont think you can use a CMR field as
part of your primary key, I think you are only allowed to use CMP fields for
your primary key. Read the specs, if I am wrong then I think this is best
place and time for me to get corrected.

Best wishes


EDWARD BANFA

NETPLAY TECHNOLOGIES INC.
JOS, PLATEAU STATE
NIGERIA.




Message: 5
Subject: RE: [Xdoclet-user] CMR & Primary Key
Date: Thu, 19 Feb 2004 10:12:51 -0800
From: "Harkness, David" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]

Mohammed Khaffar wrote:
> I am trying a to use a CMR field as a part of a composite primary
> key. However the genreated BeanClassPK doesn't include that field as
> part of the PK even though I have the tag @ejb.pk-field for this
> filed.  =20
>=20
> Any ideas? Can you not use a CMR field as part of a primary key?

The problem is that the PK class must be Serializable, but EJBObject
stubs aren't.

In my beans I also map the FK as an attribute. Could you do the same and
then mark the FK as being part of the PK? For example, a User has many
Addresses, but Addresses are not shared (User 1:N Address ). You want
the PK for Address to be User.PK + Address.type (home, work, Swiss Alps
Hideaway).

User has PK called ID (Integer)

  /**
   * @ejb.pk-field
   * @ejb.persistence
   *      column-name=3D"id"
   */
  public abstract Integer getId ( ) ;

  /**
   * @ejb.relation
   *      name=3D"User-Address"
   */
  public abstract Collection getAddresses ( ) ;


Address has PK called AddressPK (Integer userId, Integer typeCode)

  /**
   * @ejb.relation
   *      name=3D"User-Address"
   */
  public abstract UserLocal getUser ( ) ;

  /**
   * @ejb.pk-field
   * @ejb.persistence
   *      column-name=3D"user_id"
   */
  public abstract Integer getUserId ( ) ;

  /**
   * @ejb.pk-field
   * @ejb.persistence
   *      column-name=3D"type_cd"
   */
  public abstract Integer getTypeCode ( ) ;

Does this makes sense? I just thought of one possible problem: you need
to create and return the PK from AddressEJB.ejbCreate(...), but to do
this you need the User's ID. However, AddressEJB.getId() can't return a
value until you call AddressEJB.setUser(UserLocal), but you can't do
that until ejbPostCreate(...). It's a little convoluted, but I think the
following will work.

AddressEJB

  public AddressPK ejbCreate ( UserLocal user, Integer typeCode, ... )
  {
    AddressPK pk =3D new AddressPK((Integer) user.getPrimaryKey(),
typeCode);
   =20
    // Fill in other attributes
    // ...
   =20
    return pk;
  }

  public void ejbPostCreate ( UserLocal user, Integer typeCode, ... )
  {
    setUser(user);
  }

Good luck!

David Harkness
Sr. Software Engineer
Sony Pictures Digital Networks
(310) 482-4756





-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to