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.
>
> 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="id"
*/
public abstract Integer getId ( ) ;
/**
* @ejb.relation
* name="User-Address"
*/
public abstract Collection getAddresses ( ) ;
Address has PK called AddressPK (Integer userId, Integer typeCode)
/**
* @ejb.relation
* name="User-Address"
*/
public abstract UserLocal getUser ( ) ;
/**
* @ejb.pk-field
* @ejb.persistence
* column-name="user_id"
*/
public abstract Integer getUserId ( ) ;
/**
* @ejb.pk-field
* @ejb.persistence
* column-name="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 = new AddressPK((Integer) user.getPrimaryKey(),
typeCode);
// Fill in other attributes
// ...
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_id56&alloc_id438&op=click
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user