Hi. 

My apologies if this question betrays my status as an EJB neophyte. I
_think_ it's a JBoss question, not a general EJB question. Here goes:

I'm having a bit of trouble declaring a many-to-many relationship on
one of my CMP beans. Specifically, I want to create trees (i.e.,
graphs with no cycles) with the beans. I've implemented this by
declaring a collection to hold a bean's parent beans and a collection
to hold its child beans, and relating them via an M2M relation.

The trouble is, I haven't made my intent clear to JBoss -- when I
deploy the bean, it stores the collections of parent and child nodes
as serialized objects, rather than as CMP-related fields in a relation
table. (For instance, if I add a bean X to bean Y's list of children,
the container just serializes Y's collection of children into a blob,
rather than writing the relation to a relation table.)

The relevant snippet of code is:

    /**
     * Retrieve the Policy's ChildPolicies. Note that only AND and OR policies 
actually use these. 
     *
     * @return Returns the Policy's ChildPolicies as a Collection
     *
     * @ejb:persistent-field
     *
     * @ejb:relation name="PolicyHierarchy" 
     *               role-name="policy-has-children" 
     *
     * @jboss.relation related-pk-field="id" fk-column="CpolicyIdFkchild"
     * @jboss.relation-mapping style="relation-table"
     * @jboss.relation-table table-name="policytrees"
     * @jboss:create-table create="true"
     * @jboss:remove-table remove="true"
     * @ejb:interface-method view-type="local"
     **/

    public abstract Collection getChildPolicies();
 
    /**
     * Set the Policy's ChildPolicies
     *
     * @param pChildPolicies The Policy's ChildPolicies
     * @ejb:interface-method view-type="local"
     **/

    public abstract void setChildPolicies( Collection pChildPolicies );


    /**
     * Retrieve the Policy's ParentPolicies. Note that only AND and OR policies 
actually use these. 
     *
     * @return Returns the Policy's ParentPolicies as a Collection. 
     *
     * @ejb:persistent-field
     *
     * @ejb:relation name="PolicyHierarchy" 
     *               role-name="policy-has-parents" 
     * @jboss:relation related-pk-field="id" fk-column="CpolicyIdFkparent"
     * @jboss.relation-mapping style="relation-table"
     * @jboss.relation-table table-name="policytrees"
     * @ejb:interface-method view-type="local"
     **/

    public abstract Collection getParentPolicies();
 
    /**
     * Set the Policy's ParentPolicies. 
     *
     * @param pParentPolicies The Policy's ParentPolicies
     * @ejb:interface-method view-type="local"
     **/

    public abstract void setParentPolicies( Collection pParentPolicies );


When I compile and deploy, this bean creates the following table in
the database:

mysql> describe Policy;
+----------------+---------------------+------+-----+---------+-------+
| Field          | Type                | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+
| Id             | varchar(255) binary |      | PRI |         |       |
| Name           | varchar(255) binary | YES  |     | NULL    |       |
| MetaPolicyName | varchar(255) binary | YES  |     | NULL    |       |
| IsTLP          | tinyint(4)          | YES  |     | NULL    |       |
| isReady        | tinyint(4)          | YES  |     | NULL    |       |
| AttributeTable | longblob            | YES  |     | NULL    |       |
| childPolicies  | longblob            | YES  |     | NULL    |       |
| parentPolicies | longblob            | YES  |     | NULL    |       |
+----------------+---------------------+------+-----+---------+-------+

Note the last two fields: the container evidently thinks I wanted to
serialize the collections to childPolicies and parentPolicies, rather
than store them as relations in the table "policytrees".[0] (It does
create `policytrees'; it just doesn't use it.)

Is there some obvious mistake I've made in the xdoclet tags?
(Following the template[1], I've used xdoclet to generate all of the
.xml files).

Many thanks in advance,

--Joe Barillari



[0] Incidentally, if I don't declare the relation-table's name
explicitly, the container generates it using the bean's name. However,
because the bean's name has a slash in it (@ejb:bean
name="test/Policy"), this makes mysql choke). I assume this is a bug
-- if `/' can't appear in identifiers, the container should issue a
warning.

[1] I've based this bean on the template by Andreas
Schaefer in JBoss.3.0TemplateAndExamples.zip.


Attachment: msg25847/pgp00000.pgp
Description: PGP signature

Reply via email to