Couple things:
1) You forgot this method-level tag in your relationships:
@jboss.relation-mapping
style="foreign-key"
Without it, JBoss will use 'relation-table' mapping which is the 3rd table
you're generating (CATEGORY-XGROUP-XGROUP-CATEGORIES).
2) It looks like you're defining a uni-directional relationship.
Bi-directional would be more like:
(In XGroup)
/**
* @ejb.interface-method
*
* @ejb.relation
* name="Group-Category"
* role-name="GroupHasCategories"
*
* @jboss.relation-mapping style="foreign-key"
*/
public abstract Collection getCategories();
--------------------------------------------------------------
(In Category)
/**
* @ejb.interface-method
*
* @ejb.relation
* name="Group-Category"
* role-name="CategoryInGroup"
*
* @jboss.relation-mapping style="foreign-key"
*
* @jboss.relation
* fk-constraint="true"
* fk-column="group_fk"
* related-pk-field="id"
*/
public abstract XGroupLocal getXGroup();
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of harm de
laat
Sent: Thursday, July 10, 2003 1:25 PM
To: [EMAIL PROTECTED]
Subject: [Xdoclet-user] CMR relations fail
Hi all,
I'm trying to create a J2EE application which should be deployed on JBoss.
Right now I'm struggeling with CMR relations. I have tried a lot, and
looked into the XPetstore sample application to get my Xdoclet tags
right. But everything has failed.
I hope you guys can help.
I want to create a CMR relation between to (Entity) beans as follows:
+--------------+ +-----------------+
| XGroup | | Category |
| |- 1------0+ --| |
+--------------+ +-----------------+
So, this is a bidirectional 1-n relation. Where each XGroup can contain
zero or more Categories.
Each category has exactly one parent, which is a XGroup object.
My code get's deployed without any problems. But JBoss creates 3 tables:
CATEGORY,
XGROUP, and
CATEGORY-XGROUP-XGROUP-CATEGORIES.
I don't think it should be nessecary to have the 3th table. (2 should be
enough???)...
I don't see what is causing this.
Below is the code for my beans, and the resulting deployment descriptors.
Hope you guys can help!
Many thanks,
Harm de Laat
Informatiefabriek
The Netherlands
XGroupBean.java:
/*
* Created on Jul 7, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package nl.xbase.group.implementation;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
/**
* GroupBean.java
* @author harm
* Date: Jul 7, 2003
* @ejb.bean
* primkey-field = "id"
* name = "XGroup"
* display-name = "A container to keep categories."
* type = "CMP"
* transaction-type = "Container"
* jndi-name = "ejb/XGroup"
* local-jndi-name = "XGroup"
* view-type = "both"
* cmp-type = "2.x"
*
* @ejb.transaction type = "Required"
*/
public abstract class XGroupBean implements EntityBean {
/**
* @ejb.create-method view-type = "both"
* @param id
* @return
* @throws CreateException
*/
public String ejbCreate(String id) throws CreateException {
this.setId(id);
return null;
}
public void ejbPostCreate(String id) throws CreateException {
}
/**
* @ejb.persistent-field
* @ejb.interface-method view-type = "both"
* @ejb.pk-field
* @return
*/
public abstract String getId();
/**
* @ejb.interface-method view-type = "both"
* @param id
*/
public abstract void setId(String id);
/* CMR - fields */
/**
* @ejb.persistent-field
* @ejb.interface-method view-type = "both"
* @ejb.relation
* target-ejb = "Category"
* name = "Group-Category"
* role-name = "GroupHasCategories"
* target-role-name = "CategoryInGroup"
* target-cascade-delete = "yes"
* @jboss.relation
* fk-column = "category_fk"
* related-pk-field = "categoryId"
*/
public abstract Collection getCategories();
/**
* @ejb.interface-method view-type = "both"
* @param categories
*/
public abstract void setCategories(Collection categories);
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbLoad()
*/
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbRemove()
*/
public void ejbRemove()
throws RemoveException, EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbStore()
*/
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
*/
public void setEntityContext(EntityContext arg0)
throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#unsetEntityContext()
*/
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
}
CategoryBean.java:
/*
* Created on Jul 1, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package nl.xbase.category.implementation;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import nl.xbase.group.implementation.XGroupLocal;
/**
* CategoryBean.java
* @author harm
* Date: Jul 1, 2003
*
* @ejb.bean
* name = "Category"
* display-name = "A container to keep advertisements."
* type = "CMP"
* transaction-type = "Container"
* jndi-name = "ejb/Category"
* local-jndi-name = "Category"
* view-type = "both"
* cmp-version = "2.x"
* primkey-field = "categoryId"
* @ejb.transaction type = "Required"
*
*
*/
public abstract class CategoryBean implements EntityBean {
/**
* @ejb.create-method view-type = "both"
* @param id
* @return
* @throws CreateException
*/
public String ejbCreate(String id) throws CreateException {
this.setCategoryId(id);
return null;
}
public void ejbPostCreate(String id) throws CreateException {
}
/**
* @ejb.persistent-field
* @ejb.interface-method view-type = "both"
* @ejb.pk-field
* @return
*/
public abstract String getCategoryId();
/**
* @ejb.interface-method view-type = "both"
* @param id
*/
public abstract void setCategoryId(String id);
/* CMR - fields */
/**
* @ejb.persistent-field
* @ejb.interface-method view-type = "both"
* @ejb.relation
* name = "Group-Category"
* role-name = "CategoryInGroup"
* target-role-name = "GroupHasCategories"
* @jboss.relation
* fk-column = "group_fk"
* related-pk-field = "id"
*/
public abstract XGroupLocal getXGroup();
/**
* @ejb.interface-method view-type = "both"
* @param group
*/
public abstract void setXGroup(XGroupLocal group);
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbLoad()
*/
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbRemove()
*/
public void ejbRemove()
throws RemoveException, EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbStore()
*/
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
*/
public void setEntityContext(EntityContext arg0)
throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#unsetEntityContext()
*/
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
}
ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<!--
To add session beans that you have deployment descriptor info
for, add
a file to your XDoclet merge directory called session-beans.xml
that contains
the <session></session> markup for those beans.
-->
<!-- Entity Beans -->
<entity >
<description><![CDATA[GroupBean.java]]></description>
<display-name>A container to keep categories.</display-name>
<ejb-name>XGroup</ejb-name>
<home>nl.xbase.group.implementation.XGroupHome</home>
<remote>nl.xbase.group.implementation.XGroup</remote>
<local-home>nl.xbase.group.implementation.XGroupLocalHome</local-home>
<local>nl.xbase.group.implementation.XGroupLocal</local>
<ejb-class>nl.xbase.group.implementation.XGroupCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>XGroup</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>categories</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<!-- Write a file named ejb-finders-XGroupBean.xml if you want to
define extra finders. -->
</entity>
<entity >
<description><![CDATA[CategoryBean.java]]></description>
<display-name>A container to keep advertisements.</display-name>
<ejb-name>Category</ejb-name>
<home>nl.xbase.category.implementation.CategoryHome</home>
<remote>nl.xbase.category.implementation.Category</remote>
<local-home>nl.xbase.category.implementation.CategoryLocalHome</local-home>
<local>nl.xbase.category.implementation.CategoryLocal</local>
<ejb-class>nl.xbase.category.implementation.CategoryCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Category</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>categoryId</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>XGroup</field-name>
</cmp-field>
<primkey-field>categoryId</primkey-field>
<!-- Write a file named ejb-finders-CategoryBean.xml if you want
to define extra finders. -->
</entity>
<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml
that contains
the <entity></entity> markup for those beans.
-->
<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor
info for, add
a file to your XDoclet merge directory called
message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->
</enterprise-beans>
<!-- Relationships -->
<relationships >
<ejb-relation >
<ejb-relation-name>Group-Category</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>CategoryInGroup</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>Category</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>XGroup</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>GroupHasCategories</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>XGroup</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>categories</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
<!-- Assembly Descriptor -->
<assembly-descriptor >
<!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->
<!-- finder permissions -->
<!-- finder permissions -->
<!-- transactions -->
<container-transaction >
<method >
<ejb-name>XGroup</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction >
<method >
<ejb-name>Category</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<!-- finder transactions -->
</assembly-descriptor>
</ejb-jar>
jboss.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
<jboss>
<unauthenticated-principal>nobody</unauthenticated-principal>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jboss-beans.xml
that contains
the <session></session>, <entity></entity> and
<message-driven></message-driven>
markup for those beans.
-->
<entity>
<ejb-name>XGroup</ejb-name>
<jndi-name>ejb/XGroup</jndi-name>
<local-jndi-name>XGroup</local-jndi-name>
<method-attributes>
</method-attributes>
</entity>
<entity>
<ejb-name>Category</ejb-name>
<jndi-name>ejb/Category</jndi-name>
<local-jndi-name>Category</local-jndi-name>
<method-attributes>
</method-attributes>
</entity>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
jbosscmp-jdbc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
<jbosscmp-jdbc>
<defaults>
<preferred-relation-mapping>relation-table</preferred-relation-mapping>
</defaults>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
that contains the <entity></entity> markup for those beans.
-->
<entity>
<ejb-name>XGroup</ejb-name>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>categories</field-name>
</cmp-field>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
</entity>
<entity>
<ejb-name>Category</ejb-name>
<cmp-field>
<field-name>categoryId</field-name>
</cmp-field>
<cmp-field>
<field-name>XGroup</field-name>
</cmp-field>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Group-Category</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>CategoryInGroup</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>categoryId</field-name>
<column-name>category_fk</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>GroupHasCategories</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name>
<column-name>group_fk</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</jbosscmp-jdbc>
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user