1 Reply Latest reply on Dec 14, 2004 6:28 AM by Darran Lofthouse

    Problem deploying related beans

    czernay Newbie

      I have two entity-beans (AuthorBean, ImageBean) that should have a unidirectional one-to-one relation (Author-has-Image). I set it all up using Eclipse and XDoclet. After running XDoclet everything seems to be generated well, but it doesn't get deployed (on JBoss 4):

      ERROR [EntityContainer] Starting failed jboss.j2ee:jndiName=ejb/ImageBeanHome,service=EJB
      org.jboss.deployment.DeploymentException: Entity: de.sbow.MSys.Images.ejb.ImageBean not found for relation: Author-Image

      Investigating the ejb-jar.xml and jbosscmp-jdbc.xml I found in jbosscmp-jdbc.xml the follwing:

      <ejb-relation>
      <ejb-relation-name>Author-Image</ejb-relation-name>

      <ejb-relationship-role>

      <ejb-relationship-role-name>Author-has-Image</ejb-relationship-role-name>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>

      <ejb-relationship-role-name>Image-has-Author</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name></field-name>
      <column-name></column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>

      I wonder what I've done wrong?

      Thanks for any help
      Alexander

      AuthorBean.java
      package de.sbow.MSys.Authors.ejb;

      import java.util.Collection;

      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.RemoveException;

      import de.sbow.MSys.Authors.interfaces.AuthorBeanUtil;
      import de.sbow.MSys.Authors.value.AuthorBeanValue;
      import de.sbow.MSys.Images.ejb.ImageBean;
      import de.sbow.MSys.Images.interfaces.ImageBeanLocal;


      /**
      *
      * @ejb.bean name = "AuthorBean"
      * type = "CMP"
      * cmp-version = "2.x"
      * display-name = "AuthorBean"
      * description = "AuthorBean EJB"
      * view-type = "both"
      * jndi-name = "ejb/AuthorHome"
      * local-jndi-name = "ejb/AuthorLocalHome"
      * primkey-field = "id"
      * schema = "Authors"
      *
      * @ejb.persistence table-name = "Authors"
      * @jboss.persistence table-name = "Authors"
      * create-table = "true"
      * remove-table = "true"
      *
      *
      * @ejb.finder signature = "java.util.Collection findAll()"
      * query = "select Object(l) from Authors as l"
      *
      * @ejb.finder signature = "java.util.Collection findByName(java.lang.String name)"
      * query = "select Object(l) from Authors as l where l.name = ?1"
      *
      * @ejb.finder signature = "de.sbow.MSys.Authors.interfaces.AuthorBeanLocal findById(java.lang.String id)"
      * query = "select Object(l) from Authors as l where l.id = ?1"
      *
      *
      * @ejb.util
      * generate="physical"
      *
      * @ejb.value-object
      */
      public abstract class AuthorBean implements EntityBean {

      /** The EntityContext */
      private EntityContext context;

      /**
      *
      * @ejb.create-method
      */
      public String ejbCreate() throws CreateException {
      this.setId(AuthorBeanUtil.generateGUID(this));
      return null;
      }

      /**
      * @ejb.create-method
      * @param name
      * @param description
      * @return
      */
      public String ejbCreate(String name, String description) throws CreateException {
      this.setName(name);
      this.setDescription(description);
      this.setId(AuthorBeanUtil.generateGUID(this));
      return null;
      }

      /**
      * TODO check if this works!
      * @ejb.create-method
      * @param data
      * @return
      * @throws CreateException
      */
      public String ejbCreate(AuthorBeanValue data) throws CreateException {
      this.setId(AuthorBeanUtil.generateGUID(this));
      //data.setId(this.getId());
      this.setAuthorBeanValue(data);
      return null;
      }
      /**
      *
      * @throws CreateException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbPostCreate() throws CreateException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbActivate() throws EJBException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbPassivate() throws EJBException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbLoad() throws EJBException {
      }
      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbStore() throws EJBException {
      }
      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      *
      * @throws RemoveException Thrown if the enterprise bean does not allow destruction of the object.
      */
      public void ejbRemove() throws EJBException, RemoveException {
      }

      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void setEntityContext(EntityContext newContext) throws EJBException {
      context = newContext;
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void unsetEntityContext() throws EJBException {
      context = null;
      }



      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "author_id"
      * @ejb.pk-field
      * @return
      */
      public abstract String getId();

      /**
      * @ejb.interface-method view-type = "local"
      * @param id
      */
      public abstract void setId(String id);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "name"
      * @return
      */
      public abstract String getName();

      /**
      * @ejb.interface-method view-type = "local"
      *
      * @param name
      */
      public abstract void setName(String name);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "description"
      * @return
      */
      public abstract String getDescription();

      /**
      * @ejb.interface-method view-type = "local"
      *
      * @param description
      */
      public abstract void setDescription(String description);


      /**
      * @ejb.relation name = "Author-Image"
      * role-name = "Author-has-Image"
      * target-ejb = "de.sbow.MSys.Images.ejb.ImageBean"
      * target-role-name = "Image-has-Author"
      *
      * @jboss.relation
      * related-pk-field="image_id?
      * fk-column="image_fk?
      * fk-constraint = "true"
      *
      *
      * @ejb.interface-method view-type = "both"
      * @return
      */
      public abstract ImageBeanLocal getImage();

      /**
      * @ejb.interface-method view-type = "both"
      * @param image
      */
      public abstract void setImage(ImageBeanLocal image);

      /**
      * @ejb:relation name = "MediaObject-Authors"
      * role-name = "Authors-has-MediaObjects"
      * cascade-delete = "false"
      * target-ejb = "de.sbow.MSys.MediaArchive.ejb.MediaObject"
      * target-role-name = "MediaObjects-has-Authors"
      * target-multiple = "yes"
      *
      * @jboss:relation-table table-name = "MediaObject2Author"
      * create-table = "true"
      * remove-table = "true"
      *
      * @jboss:relations-mapping style = "relation.table"
      *
      * @jboss:relation related-pk-field = "id"
      * fk-column = "author_id"
      * fk-constraint = "false"
      *
      * @return
      */
      public abstract Collection getMediaObjects();

      /**
      * @ejb:interface-method
      * @param mediaObjects
      *
      */
      public abstract void setMediaObjects(Collection mediaObjects);


      /**
      * @ejb.interface-method view-type = "both"
      *
      * @return
      */
      public abstract AuthorBeanValue getAuthorBeanValue();

      /**
      * @ejb.interface-method view-type = "both"
      * @param data
      */
      public abstract void setAuthorBeanValue(AuthorBeanValue data);

      }

      ImageBean.java
      package de.sbow.MSys.Images.ejb;


      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.RemoveException;

      import de.sbow.MSys.Images.interfaces.ImageBeanUtil;


      /**
      * @ejb.bean name = "ImageBean"
      * type = "CMP"
      * cmp-version = "2.x"
      * display-name = "ImageBean"
      * description = "ImageBean EJB"
      * view-type = "both"
      * jndi-name = "ejb/ImageBeanHome"
      * local-jndi-name = "ejb/ImageBeanLocalHome"
      * primkey-field = "id"
      * schema = "Images"
      *
      * @ejb.persistence table-name = "Images"
      * @jboss.persistence table-name = "Images"
      * create-table = "true"
      * remove-table = "true"
      *
      *
      * @ejb.finder signature = "java.util.Collection findAll()"
      * query = "select Object(l) from Images as l"
      *
      * @ejb.finder signature = "java.util.Collection findByName(java.lang.String name)"
      * query = "select Object(l) from Images as l where l.name = ?1"
      *
      * @ejb.finder signature = "de.sbow.MSys.Images.interfaces.ImageBeanLocal findById(java.lang.String id)"
      * query = "select Object(l) from Images as l where l.id = ?1"
      *
      * @ejb:util
      * generate="physical"
      *
      * @ejb.value-object
      */
      public abstract class ImageBean implements EntityBean {

      /** The EntityContext */
      private EntityContext context;

      /**
      *
      * @throws CreateException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      *
      * @ejb.create-method
      */
      public String ejbCreate() throws CreateException {
      this.setId(ImageBeanUtil.generateGUID(this));
      return null;
      }

      /**
      *
      * @throws CreateException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbPostCreate() throws CreateException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbActivate() throws EJBException {
      }

      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbPassivate() throws EJBException {
      }

      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbLoad() throws EJBException {
      }

      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void ejbStore() throws EJBException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      *
      * @throws RemoveException Thrown if the enterprise bean does not allow destruction of the object.
      */
      public void ejbRemove() throws EJBException, RemoveException {
      }

      /**
      *
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void setEntityContext(EntityContext newContext) throws EJBException {
      context = newContext;
      }

      /**
      * @throws EJBException Thrown if the instance could not perform
      * the function requested by the container because of an system-level error.
      */
      public void unsetEntityContext() throws EJBException {
      context = null;
      }

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "image_id"
      * @ejb.pk-field
      * @return
      */
      public abstract String getId();

      /**
      * @ejb.interface-method view-type = "local"
      * @param id
      */
      public abstract void setId(String id);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "image"
      * @return
      */
      public abstract byte[] getImage();

      /**
      * @ejb.interface-method view-type = "local"
      * @param image
      */
      public abstract void setImage(byte[] image);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "type"
      * @return
      */
      public abstract String getType();

      /**
      * @ejb.interface-method view-type = "local"
      * @param type
      */
      public abstract void setType(String type);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "width"
      * @return
      */
      public abstract int getWidth();

      /**
      * @ejb.interface-method view-type = "local"
      * @param width
      */
      public abstract void setWidth(int width);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "height"
      * @return
      */
      public abstract int getHeight();

      /**
      * @ejb.interface-method view-type = "local"
      * @param height
      */
      public abstract void setHeight(int height);

      /**
      * @ejb.interface-method view-type = "local"
      * @ejb.persistence column-name = "colors"
      * @return
      */
      public abstract int getColors();

      /**
      * @ejb.interface-method view-type = "local"
      * @param int
      */
      public abstract void setColors(int colors);

      }