I am using jboss 3.2.2.  Here are the class defs for the bean and a test
client that I have been using.  Please let me know if you need anything
else...

RecipeGrainBean.java

package homebrew.ejb.entity;

// homebrew.ejb.interfaces imports
import homebrew.ejb.entity.vo.RecipeGrainBeanValue;
import homebrew.ejb.entity.reference.interfaces.RefRecipeGrainBeanLocal;

// javax.ejb imports
import javax.ejb.CreateException;
// org.apache.log4j imports
import org.apache.log4j.Logger;
import java.sql.Timestamp;
import homebrew.ejb.util.db.GetTimestamp;
import java.rmi.RemoteException;

/**
*
*       Class representing recipe grain information stored in the database.
*       Class maintains grain information such as grain type (grain
reference id),
*       the recipe to which the grain belongs, and the total weight in
*       pounds being added to the recipe.
*
*       Methods exists to get and set the grain value object.
*
*       @author Matthew Hanson
*
*       @ejb.bean name="RecipeGrainBean"
*               display-name="Recipe grain"
*               local-jndi-name="homebrew/ejb/entity/RecipeGrainBean"
*               view-type="local"
*               type="CMP"
*               schema="recipe_grain"
*
*       @ejb.home generate="local"
*
*       @ejb.interface generate="local"
*
*       @ejb.pk extends="java.lang.Object"
*
*       @ejb.transaction type="Required"
*
*       @ejb.value-object match="*"
*
*       @jboss.persistence
*               datasource="java:/DefaultDS"
*               datasource-mapping="Hypersonic SQL"
*               table-name="recipe_grain"
*
*       @jboss.entity-command
*               name="hsqldb-fetch-key"
*
*       @ejb.persistence table-name="recipe_grain"
*
*       @ejb.facade
*
*       @ejb.util
*               generate="physical"
*/
public abstract class RecipeGrainBean extends DefaultEntityBean {
        
        private static Logger logger =
Logger.getLogger(RecipeGrainBean.class);
        
        /**
        *       @ejb.pk-field
        *       @ejb.persistent-field
        *       @ejb.interface-method
        *
        *       @ejb.persistence
        *
        *       @jboss.column-name name="recipe_grain_id"
        *
        *       @jboss.auto-increment
        *
        *       @return The primary key of the recipe grain
        *
        *       Get the primary key of the recipe grain
        */
        public abstract Integer getRecipeGrainId();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="recipe_grain_id"
        *       @jboss.persistence auto-increment="true"
        *       @jboss.auto-increment
        *
        *       @param  theRecipeGrainId        The primary key to be
assigned to the recipe grain
        *
        *       Set the primary key of the recipe grain
        */
        public abstract void setRecipeGrainId(Integer theRecipeGrainId);
        
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistence
        *       @ejb.interface-method
        *
        *       @jboss.column-name name="recipe_id"
        *
        *       @return The primary key of the recipe to which the grain
belongs
        *
        *       Get the primary key of the recipe to which the grain belongs
        */
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="created_timestamp"
        *
        *       @param  theCreatedTimeStamp     The create timestamp value
to be assigned
        *
        *       Set the created timestamp
        */
        public abstract void setCreatedTimestamp(Timestamp
theCreatedTimeStamp);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="created_timestamp"
        *
        *       @return The timestamp for when the account was created
        *
        *       Get the created timestamp
        */
        public abstract Timestamp getCreatedTimestamp();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="modified_timestamp"
        *
        *       @return The timestamp for when the account was modified
        *
        *       Get the modified timestamp
        */
        public abstract Timestamp getModifiedTimestamp();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="modified_timestamp"
        *
        *       @param  theModifiedTimeStamp    The modified timestamp value
to be assigned
        *
        *       Set the modified timestamp
        */
        public abstract void setModifiedTimestamp(Timestamp
theModifiedTimeStamp);
        public abstract Integer getRecipeId();
        /**
        *       @ejb.interface-method view="local"
        *
        *       @param  theRecipeId     The primary of the recipe to which
        *       the grain is to be assigned
        *
        *       Set the primary key of the recipe to which the grain belongs
        */
        public abstract void setRecipeId(Integer theRecipeId);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistence
        *       @ejb.interface-method
        *
        *       @jboss.column-name name="ref_recipe_grain_id"
        *
        *       @return Key to the grain reference table
        *
        *       Get the key to this grain in the reference table.
        *       Grain reference table maintains a master
        *       list of all available grains and their general
characteristics.
        */
        public abstract Integer getGrainRefId();
        /**
        *       @ejb.interface-method view="local"
        *
        *       @param  theGrainRefId   The key to the grain reference table
        *
        *       Assign the grain reference table key to the grain
        */
        public abstract void setGrainRefId(Integer theGrainRefId);
        /**
         * Set the total pound weight of the added grain
         * 
         * @param theLbs        Grain weight in ounces
         */
        public abstract void setLbs(Double theLbs);
        
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.interface-method
        *       @ejb.persistence
        *
        *       @jboss.column-name name="lbs"
        *       @jboss.persistence
        *
        *       @return Grain weight in ounces
        *
        *       Set the total pound weight of the added grain
        */
        public abstract Double getLbs();
        
        //      begin 1:1 grain reference relationship
        //      1.      aggregate-name is the name of the container
        //              in the value object holding the n grain value
objects
        //      2.      aggregate is the type of value object being
        //              held by the container
        //      3.      members-name is the method signature for the
        //              add/remove methods for grain reference in the recipe
grain CMP class
        //      4.      members is the local interface to the grain
reference bean
        //              used by the add/remove methods in the recipe CMP
class
        /**
        *       @ejb:interface-method view="local"
        * 
        *       @ejb.relation
        *               name="Grain-GrainReference"
        *               role-name="Grain-Has-Reference"
        *               target-ejb="RefRecipeGrainBean"
        *               target-role-name="Reference-Of-Grain"
        *
        *       @ejb.value-object
        *
aggregate="homebrew.ejb.entity.reference.vo.RefRecipeGrainBeanValue"
        *               aggregate-name="GrainReference"
        *
members="homebrew.ejb.entity.reference.interfaces.RefRecipeGrainBeanLocal"
        *               members-name="RefRecipeGrain"
        *               relation="external"
        *
        *       @jboss.relation
        *               related-pk-field="recipeGrainId"
        *               fk-column="ref_recipe_grain_id"
        *
        *       @jboss.target-relation fk-column="recipe_grain_id"
        *               related-pk-field="recipeGrainId"
        *
        *       @return Grain reference beans
        *
        *       Method to get the reference grain 1-side of the 1:1
        *       grain:reference grain relationship.  This method provides
        *       a local interace ([EMAIL PROTECTED]
homebrew.ejb.entity.interfaces.RefRecipeGrainBeanLocal
RefRecipeGrainBeanLocal})
        *       to each grain reference bean associated with this grain
        */
        public abstract RefRecipeGrainBeanLocal getRefRecipeGrain();
        /**
         * @ejb.interface-method
         * 
         * @param theRefRecipeGrain
         */
        public abstract void setRefRecipeGrain(RefRecipeGrainBeanLocal
theRefRecipeGrain);
        
        /**
        *       @ejb.interface-method view="local"
        *
        *       @return The grain value object
        *
        *       @see    homebrew.ejb.entity.vo.RecipeGrainBeanValue
RecipeGrainBeanValue
        *
        *       Get the grain value object
        */
        public abstract RecipeGrainBeanValue getRecipeGrainBeanValue();
        /**
        *       @ejb.interface-method view="local"
        *
        *       @param  theRecipeGrainBeanValue The grain value object to
assign
        *
        *       @see    homebrew.ejb.entity.vo.RecipeGrainBeanValue
RecipeGrainBeanValue
        *
        *       Set the grain value object
        */      
        public abstract void setRecipeGrainBeanValue(RecipeGrainBeanValue
theRecipeGrainBeanValue);
        
        /**
        *
        *       @ejb.create-method
        *
        *       @param  theValue The grain value object
        *
        *       @return null
        *
        *       @throws CreateException Unable to create the grain bean.
        *
        *       ejbCreate by grain bean value object required per EJB spec
        *       to set (non-primary key) CMP fields
        */
        public java.lang.Object ejbCreate(RecipeGrainBeanValue theValue)
throws CreateException
        {
                logger.info("in recipe grain bean ejbCreate for value
object...");
        
theValue.setCreatedTimestamp(GetTimestamp.CurrentTimestamp());
        
theValue.setModifiedTimestamp(theValue.getCreatedTimestamp());
                this.setCreatedTimestamp(theValue.getCreatedTimestamp());
                this.setModifiedTimestamp(theValue.getModifiedTimestamp());
                this.setRecipeGrainBeanValue(theValue);
                /*this.setGrainRefId(theValue.getGrainRefId());
                this.setLbs(theValue.getLbs());*/
                return null;
        }
        /**
         * 
         * ejbPostCreate by recipe value object method required per EJB spec
         * 
         * @param theValue      The grain value object
         * 
         * @throws      CreateException Unable to create the grain bean.
         */
        public void ejbPostCreate(RecipeGrainBeanValue theValue) throws
CreateException
        {
        }
        
        /**
         * ejbStore method used to update fields
         * such as modified timestamp
         */
        public void ejbStore() throws RemoteException
        {
                logger.info("In RecipeGrainBean.ejbStore()");
                this.setModifiedTimestamp(GetTimestamp.CurrentTimestamp());
                logger.info("New recipe grain modified time = "
                        + this.getModifiedTimestamp().toString());
        }
}

RefRecipeGrainBean.java:

package homebrew.ejb.entity.reference;

import homebrew.ejb.entity.DefaultEntityBean;
import homebrew.ejb.entity.reference.vo.RefRecipeGrainBeanValue;

import org.apache.log4j.Logger;

/**
*
*       Class representing the grain reference information as stored in the
database.
*       Recipe grain beans are stored with a foreign key to the reference
*       date.  This key provides access to the general attributes of the
specific
*       grain used in the recipe.
*
*       Methods exists to get and set the account holder value object.
*
*       @author Matthew Hanson
*
*       @ejb.bean name="RefRecipeGrainBean"
*               display-name="Grain reference information"
*
local-jndi-name="homebrew/ejb/entity/reference/RefRecipeGrainBean"
*               view-type="local"
*               type="CMP"
*               schema="ref_recipe_grain"
*               reentrant="true"
*
*       @ejb.home generate="local"
*
*       @ejb.interface generate="local"
*
*       @ejb.pk extends="java.lang.Object"
*
*       @ejb.transaction type="Required"
*
*       @ejb.value-object match="*"
*
*       @jboss.table-name table-name="ref_recipe_grain"
*
*       @ejb.finder
*               view-type="local"
*               signature="java.util.Collection findAll()"
*               query="SELECT OBJECT(a) FROM ref_recipe_grain AS a"
*
*       @ejb.util
*               generate="physical"
*
*/
public abstract class RefRecipeGrainBean extends DefaultEntityBean
{
        private static Logger logger =
Logger.getLogger(RefRecipeGrainBean.class);
        
        /**
        *       Get the reference grain primary key
        *       @return Reference grain primary key
        *
        *       @ejb.pk-field
        *       @ejb.persistent-field
        *       @ejb.interface-method
        *
        *       @ejb.persistence
        *
        *       @jboss.column-name name="recipe_grain_id"
        */
        public abstract Integer getRecipeGrainId();
        /**
         * Set the reference grain primary key
         * 
         * @param theGrainId    The reference grain primary key
         */
        public abstract void setRecipeGrainId(Integer theGrainId);
        /**
        *       Get the reference grain name
        *       @return Reference grain name
        *
        *       @ejb.interface-method view="local"
        *       @ejb.interface-method
        *       @ejb.persistence
        *
        *       @jboss.column-name name="recipe_grain_name"
        *       @jboss.persistence
        */
        public abstract String getRecipeGrainName();
        /**
         * Set the reference grain name
         * 
         * @param theGrainName  The recipe grain name
         */
        public abstract void setRecipeGrainName(String theGrainName);
        
        /**
        *       Get the reference grain value object
        *       @return The reference grain value object
        *       @see    homebrew.ejb.entity.vo.RefRecipeGrainBeanValue
RefRecipeGrainBeanValue
        *
        *       @ejb.interface-method view="local"
        */
        public abstract RefRecipeGrainBeanValue
getRefRecipeGrainBeanValue();
}

OutputAccountRecipesGrains.java:

/*
 * Created on Dec 16, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package homebrew.testing.client.accountrecipegraincmr;

import homebrew.ejb.entity.vo.AccountHolderBeanValue;
import homebrew.ejb.entity.vo.AccountRecipeBeanValue;
import homebrew.ejb.entity.vo.RecipeHopsBeanValue;
import homebrew.ejb.entity.vo.RecipeGrainBeanValue;
import homebrew.ejb.session.interfaces.AccountFacade;
import homebrew.ejb.session.interfaces.AccountFacadeHome;
import homebrew.ejb.session.util.AccountFacadeUtil;
import homebrew.testing.TestArgs;
import jargs.gnu.CmdLineParser;

/**
 * @author MD1MHAN1
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class OutputAccountRecipesGrains {

        public static void main(String[] args) {
                try {
                        TestArgs theArgs = null;
                        try {
                                theArgs = new TestArgs(args);
                                System.out.println(
                                        "Getting recipes for account email
'"
                                                + theArgs.getAcctEmail()
                                                + "'");
                        } catch (CmdLineParser.IllegalOptionValueException
iox) {
                                System.out.println("Illegal option:  " +
iox.getMessage());
                                System.exit(1);
                        } catch (CmdLineParser.UnknownOptionException uox) {
                                System.out.println("Unknown option:  " +
uox.getMessage());
                                System.exit(1);
                        }
                        
                        AccountFacadeHome acctHome =
AccountFacadeUtil.getHome();
                        System.out.println(
                                "Client has home interface:  " +
acctHome.toString());

                        AccountFacade acct = acctHome.create();
                        System.out.println(
                                "Client has AccountFacade with test string
'"
                                        + acct.getTestString()
                                        + "'");

                        AccountHolderBeanValue acctVal =
        
acct.getAccountHolder(theArgs.getAcctEmail());
                        System.out.println(
                                "Add hops account value:  " +
acctVal.toString());

                        AccountRecipeBeanValue[] acctRecipes =
acctVal.getRecipes();
                        System.out.println(
                                "acctVal account has "
                                        + acctRecipes.length
                                        + " recipes");
                        for (int l = 0; l < acctRecipes.length; ++l) {
                                System.out.println(
                                        "acctVal account recipe["
                                                + l
                                                + "] = "
                                                +
acctRecipes[l].toString());
                                
                                RecipeHopsBeanValue[] recipeHops =
acctRecipes[l].getHopss();
                                System.out.println(
                                        "Recipe has "
                                                + recipeHops.length
                                                + " hops");
                                for (int m = 0; m < recipeHops.length; ++m)
                                {
                                        System.out.println("Account recipe
hops["
                                                + m + "] = " +
recipeHops[m].toString());
                                }
                                RecipeGrainBeanValue[] recipeGrains =
acctRecipes[l].getGrains();
                                System.out.println(
                                        "Recipe has "
                                                + recipeGrains.length
                                                + " grains");
                                for (int m = 0; m < recipeGrains.length;
++m)
                                {
                                        System.out.println("Account recipe
grain["
                                                + m + "] = " +
recipeGrains[m].toString());
                                        System.out.println("Account recipe
reference grain["
                                                + m + "] =" +
recipeGrains[m].getGrainReference().toString());
                                }
                        }
                } catch (Exception ex) {
                        System.err.println("OutputAccountRecipesGrains
caught an unexpected exception!");
                        ex.printStackTrace();
                        System.exit(1);
                }
        }
}

Thanks, a lot!!!

Regards,
Matt Hanson

-----Original Message-----
From: Alexey Loubyansky [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 11:19 AM
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] 1:1 Unidirectional (Aggregate) Relationship
Problem


It should work fine as it does for me. What JBoss version are you using? Do
you have a testcase?

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Hanson, Matthew
> Sent: Tuesday, December 23, 2003 5:00 PM
> To: '[EMAIL PROTECTED]'
> Subject: [JBoss-user] 1:1 Unidirectional (Aggregate) 
> Relationship Problem
> 
> Hi--
> 
> We are storing the key from a reference table in another 
> table.  We would like to create a unidirectional, 1:1 
> relationship to allow the first bean to access information in 
> the reference table.  Here is basically how the table 
> relationship is setup:
> 
> tableA
> id (integer primary key)
> ref_id (integer)
> 
> tableB
> id (integer primary key)
> some data
> some data
> .
> .
> .
> 
> I was assuming that I could create the relationship such that 
> the bean container could be configured to get information 
> from tableB based on the value in the ref_id column of 
> tableA.  However, the relationship seems to be drawing info 
> from tableB based upon the value in the primary key tableA.id 
> instead.  How do I change this?
> 
> The following is the relationship configuration in ejb-jar.xml:
> 
>    <relationships >
>       <ejb-relation >
>          <ejb-relation-name>Grain-GrainReference</ejb-relation-name>
> 
>          <ejb-relationship-role >
>  
> <ejb-relationship-role-name>Grain-Has-Reference</ejb-relations
> hip-role-name>
>             <multiplicity>One</multiplicity>
>             <relationship-role-source >
>                <ejb-name>RecipeGrainBean</ejb-name>
>             </relationship-role-source>
>             <cmr-field >
>                <cmr-field-name>refRecipeGrain</cmr-field-name>
>             </cmr-field>
>          </ejb-relationship-role>
> 
>          <ejb-relationship-role >
>  
> <ejb-relationship-role-name>Reference-Of-Grain</ejb-relationsh
> ip-role-name>
>             <multiplicity>One</multiplicity>
>             <relationship-role-source >
>                <ejb-name>RefRecipeGrainBean</ejb-name>
>             </relationship-role-source>
>          </ejb-relationship-role>
> 
>       </ejb-relation>
>       .
>       .
>       .
> 
> The following is the configuration from jbosscmp-jdbc.xml:
> 
>   <relationships>
>     <ejb-relation>
>       <ejb-relation-name>Grain-GrainReference</ejb-relation-name>
> 
>       <ejb-relationship-role>
>  
> <ejb-relationship-role-name>Grain-Has-Reference</ejb-relations
> hip-role-name>
>           <key-fields>
>              <key-field>
>                <field-name>recipeGrainId</field-name>
>                <column-name>recipe_grain_id</column-name>
>              </key-field>
>           </key-fields>
> 
>       </ejb-relationship-role>
>       <ejb-relationship-role>
>  
> <ejb-relationship-role-name>Reference-Of-Grain</ejb-relationsh
> ip-role-name>
>                 <key-fields/>
> 
>       </ejb-relationship-role>
>     </ejb-relation>
>       .
>       .
>       .
> 
> I am using the xdoclet ejb.relation and jboss.target-relation 
> to facilitate the relationship.  If anyone on the off chance 
> would know the attributes that help specify this type of 
> relationship, that would be amazing...
> Otherwise, knowing how the deployment files should look would 
> even help, a lot!
> 
> Please help!
> 
> Regards,
> Matt Hanson
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills.  Sign 
> up for IBM's Free Linux Tutorials.  Learn everything from the 
> bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
> 




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to