> My question is. Does anybody has any happy experience with
> CMP/CMR entity bean inheritance?
> Is it possible? Are there any limitations or any special care
> I should take?
Inheritance doesn't work with CMR as you would expect. However, what I do
to sortof get inheritance is just put an abstract method in my top level
class which all my subclasses end up overriding when they define the
relationship.
So:
/**
* @ejb.bean name="Animal"
* type="CMP"
* generate="false"
* cmp-version="2.x"
* primkey-field="id"
*
* @jboss.entity-command name="get-generated-keys"
*/
class AnimalBean
implements EntityBean
{
/**
* This CMP field gets inherited by all subclasses just fine.
*
* @ejb.persistence
* @ejb.interface-method view-type="both"
*
* @jboss.persistence auto-increment="true"
*/
public abstract Integer getId();
/**
* This CMP field gets inherited by all subclasses just fine.
*
* @ejb.persistence
* @ejb.interface-method view-type="both"
*/
public abstract String getName();
/**
* This CMR field's accesors get inherited, however, we cannot
* specify that it is a CMR field here, EACH subclass must do it.
*/
public abstract Owner getOwner();
}
/**
* @ejb.bean name="Cat"
* type="CMP"
* cmp-version="2.x"
* schema="Cat"
*/
class CatBean
extends AnimalBean
{
/**
* This is where the CMR field gets defined.
*
* @ejb.interface-method view-type="local"
* @ejb.relation name="cat-owner"
* role-name="one-cat-has-one-owner"
* target-ejb="Owner"
* target-role-name="one-owner-has-has-many-cats"
* target-multiple="yes"
*/
public abstract Owner getOwner();
}
/**
* @ejb.bean name="Dog"
* type="CMP"
* cmp-version="2.x"
* schema="Dog"
*/
class DogBean
extends AnimalBean
{
/**
* This is where the CMR field gets defined.
*
* @ejb.interface-method view-type="local"
* @ejb.relation name="dog-owner"
* role-name="one-dog-has-one-owner"
* target-ejb="Owner"
* target-role-name="one-owner-has-has-many-dogs"
* target-multiple="yes"
*/
public abstract Owner getOwner();
}
Now, you can reference Cats and Dogs as Animals and still get their
Owners...
Maybe not the cleanest solution, but it seems to work.
Michael
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user