Hello,
 
I have recently switched from data-objects to value-objects (great feature!).  I have a problem though when trying to create a value-object for a one to one CMR composition.  The value-object that is generated is ok but the CMP object that is generated isn't (in my opinion).
 
My relation is: one Produit is composed of one TypeGroupeProduit.
 
Here are the declarations for my value-objects:
 
for the class:

* @ejb.bean name="Produit"
* view-type="both"
*
type="CMP"
* jndi-
name="client/Produit"
* local-jndi-
name="client/local/Produit"
*
* @ejb.value-
object
*
name="Produit"
*
match="*"
...

and for the method:

/**
* @ejb.value-object
* compose="com.sage.client.persist.props.CodeBarreValue"
* compose-name="CodeBarreValue"
* members="com.sage.client.persist.interfaces.CodeBarreLocal"
* members-name="CodeBarre"
* relation="external"
*
* @ejb.relation name="produit-codeBarre"
* role-name="one-produit-has-one-codeBarre"
* target-ejb="CodeBarre"
* target-role-name="one-codeBarre-belongs-to-one-produit"
* target-cascade-delete="yes"
*
* @jboss.relation
* fk-column="CODE_BARRE_ID"
* related-pk-field="id"*
* @ejb.interface-method view-type="local"
*/
public abstract CodeBarreLocal getCodeBarre();

/**
* @ejb.interface-method view-type="local"
*/
public abstract void setCodeBarre(CodeBarreLocal cb);

now if I do the following in my test code:

 

ProduitValue voProd1 = new ProduitValue();
voProd1.setId(GUID4.toString());
voProd1.setNom(NOM_PROD1);
voProd1.setVersion(VERSION1);

CodeBarreValue voCB1 = new
CodeBarreValue();
voCB1.setId(GUID7.toString());
voCB1.setOrigin(ORIGIN_CB1);

ProduitRemote prod1 = produitHome.create(voProd1);
voProd1.setCodeBarreValue(voCB1);
prod1.setProduitValue(voProd1);

 
Since it is a composition, I would expect the setProduitValue to create the CodeBarre object.  Instead the method looks for an existing CodeBarre (findByPrimaryKey) therefore I receive an ObjectNotFoundException. In the case of a composition that is one to many, or many to many I don't have this problem.  The set method will create the objects that it is composed of.  It only seems to occur in a one-to-one composition.
 
I would appreciate if someone could tell me if I am doing something wrong, if my interpretation is wrong or if this is a bug.
 
Thank you very much,
 
Fran�ois
 
PS: Here is the code generated for the setProduitValue:

public void setProduitValue( com.sage.client.persist.props.ProduitValue valueHolder )
{
    try
    {
        setNom( valueHolder.getNom() );
        setVersion( valueHolder.getVersion() );
    // Anonymous block to allow variable declations without conflicts
        {

        // Checks for null aggregate
        if (valueHolder.getCodeBarreValue() != null
)
            {
                com.sage.client.persist.interfaces.CodeBarrePK pk = new
com.sage.client.persist.interfaces.CodeBarrePK(valueHolder.getCodeBarreValue().getId());
                com.sage.client.persist.interfaces.CodeBarreLocalHome home = com.sage.client.persist.util.CodeBarreUtil.getLocalHome();
                com.sage.client.persist.interfaces.CodeBarreLocal relation = home.findByPrimaryKey(pk);
                relation.setCodeBarreValue(valueHolder.getCodeBarreValue());
            }
        }
    }
    catch
(Exception e)
    {
    throw new
javax.ejb.EJBException(e);
    }
}

 
PS2: Here is the code I think should be generated for setProduitValue


 

public void setProduitValue( com.sage.client.persist.props.ProduitValue valueHolder )
{
    try
    {
        setNom( valueHolder.getNom() );
        setVersion( valueHolder.getVersion() );
    // Anonymous block to allow variable declations without conflicts
        {

        // Checks for null aggregate
        if (valueHolder.getCodeBarreValue() != null
)
            {
                com.sage.client.persist.interfaces.CodeBarreLocalHome home = com.sage.client.persist.util.CodeBarreUtil.getLocalHome();
                com.sage.client.persist.interfaces.CodeBarreLocal relation = home.create(valueHolder.getCodeBarreValue());
                setCodeBarre(relation);
            }
        }
    }
    catch
(Exception e)
    {
 
  if(e instance of javax.ejb.CreateException) {
        throw (javax.ejb.CreateException) e;
   } else {

           throw new
javax.ejb.EJBException(e);
    }
}

 

Reply via email to