Hi,

Per your request, I have tested a bean with auto-increment primary key
fields and without foreign-key mappings.

I created a mini-project for Jboss 3.2.2 comprised of only a single bean
class that should have Hypersonic auto-increment and create a primary key
for the bean.  The bean has no relationships at all and does have the
auto-increment tag.  Additionally, just for thoroughness, all of the
<insert-after-ejb-post-create> tags in standardjboss.xml are set to true.
The null primary key exception was thrown again.

Here is the bean:

package homebrew.ejb.entity;

// javax.ejb imports
import homebrew.ejb.interfaces.accountHolderBeanPK;
import homebrew.ejb.interfaces.accountHolderBeanData;
import homebrew.ejb.interfaces.accountHolderBeanValue;

import java.util.Collection;

import javax.ejb.CreateException;

/**
*
*       @ejb.bean name="accountHolderBean"
*               display-name="General account information"
*               local-jndi-name="homebrew/ejb/entity/accountHolderBean"
*               view-type="local"
*               type="CMP"
*               schema="account"
*               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="account"
*
*       @jboss.entity-command
*               name="hsqldb-fetch-key"
*
*       @ejb.finder
*               view-type="local"
*               signature="java.util.Collection findByEmailAddress(
java.lang.String theEmailAddress )"
*               query="SELECT OBJECT(a) FROM account AS a WHERE
a.emailAddress = ?1"
*
*       @ejb.facade
*
*       @ejb.util
*               generate="physical"
*/
public abstract class accountHolderBean extends defaultEntityBean
{
        /**
        *       @ejb.pk-field
        *       @ejb.persistent-field
        *       @ejb.interface-method
        *
        *       @ejb.persistence
        *
        *       @jboss.column-name name="account_id"
        *
        *       @jboss.persistence auto-increment="true"
        *       @jboss.auto-increment
        */
        public abstract Integer getAccountId();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="account_id"
        *
        *       @jboss.persistence auto-increment="true"
        *       @jboss.auto-increment
        */
        public abstract void setAccountId(Integer theAccountId);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="account_role_id"
        */
        public abstract void setAccountRoleId(Integer theAccountRoleId);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="account_role_id"
        */
        public abstract Integer getAccountRoleId();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="email_address"
        */
        public abstract String getEmailAddress();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="email_address"
        */
        public abstract void setEmailAddress(String theEmailAddress);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="email_type_cd"
        */
        public abstract String getEmailTypeCd();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="email_type_cd"
        */
        public abstract void setEmailTypeCd(String theEmailTypeCd);
        
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="account_password"
        */
        public abstract String getAccountPassword();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="account_password"
        */
        public abstract void setAccountPassword(String theAccountPassword);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="first_name"
        */
        public abstract String getFirstName();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="first_name"
        */
        public abstract void setFirstName(String theFirstName);
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="ssn"
        */
        public abstract Integer getSSN();
        /**
        *       @ejb.interface-method view="local"
        *       @ejb.persistent-field
        *
        *       @jboss.column-name name="ssn"
        */
        public abstract void setSSN(Integer theSSN);
        /**
        *       @ejb.interface-method view="local"
        */
        public abstract accountHolderBeanData getData();
        /**
        *       @ejb.interface-method view="local"
        */      
        public abstract void setData(accountHolderBeanData theData);
        
        /**
        *       @ejb.interface-method view="local"
        */
        public abstract accountHolderBeanValue getaccountHolderBeanValue();
        /**
        *       @ejb.interface-method view="local"
        */      
        public abstract void
setaccountHolderBeanValue(accountHolderBeanValue theAccountHolderValue);
        
        /**
        *
        *       @ejb.create-method
        */
        public java.lang.Object ejbCreate(accountHolderBeanValue theValue)
throws CreateException
        {
                System.out.println("in ejbCreate for value object...");
                
                /*setAccountRoleId(new Integer(1));
                setEmailAddress(theValue.getEmailAddress());
                setEmailTypeCd(theValue.getEmailTypeCd());
                setAccountPassword(theValue.getAccountPassword());*/
                this.setaccountHolderBeanValue(theValue);
                
                return null;
        }
        public void ejbPostCreate(accountHolderBeanValue theValue) throws
CreateException
        {
        }
        
        /**
        *
        *       @ejb.create-method
        */
        public java.lang.Object ejbCreate(String theEmailAddress,
                String theEmailTypeCd,
                String theAccountPassword) throws CreateException
        {
                System.out.println("in ejbCreate for email address...");
                
                setAccountRoleId(new Integer(1));
                setEmailAddress(theEmailAddress);
                setEmailTypeCd(theEmailTypeCd);
                setAccountPassword(theAccountPassword);
                
                return null;
        }
        
        public void ejbPostCreate(String theEmailAddress,
                String theEmailTypeCd,
                String theAccountPassword) throws CreateException
        {
                this.setAccountId(((accountHolderBeanPK)
entityCtx.getPrimaryKey()).getAccountId());
        }
}

Here is the jbosscmp-jdbc.xml (with auto-increment tag):

<?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>
     <datasource>java:/DefaultDS</datasource>
     <datasource-mapping>Hypersonic SQL</datasource-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>accountHolderBean</ejb-name>
         <table-name>account</table-name>

         <cmp-field>
            <field-name>accountId</field-name>
            <column-name>account_id</column-name>

                        <auto-increment/>
        </cmp-field>
         <cmp-field>
            <field-name>accountRoleId</field-name>
            <column-name>account_role_id</column-name>

        </cmp-field>
         <cmp-field>
            <field-name>emailAddress</field-name>
            <column-name>email_address</column-name>

        </cmp-field>
         <cmp-field>
            <field-name>emailTypeCd</field-name>
            <column-name>email_type_cd</column-name>

        </cmp-field>
         <cmp-field>
            <field-name>accountPassword</field-name>
            <column-name>account_password</column-name>

        </cmp-field>
         <cmp-field>
            <field-name>firstName</field-name>
            <column-name>first_name</column-name>

        </cmp-field>
         <cmp-field>
            <field-name>SSN</field-name>
            <column-name>ssn</column-name>

        </cmp-field>

        <entity-command name="hsqldb-fetch-key">
        </entity-command>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
      </entity>

   </enterprise-beans>

</jbosscmp-jdbc>

Thanks for all of the help so far!

Regards,
Matt Hanson

-----Original Message-----
From: Alexey Loubyansky [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 04, 2003 3:31 PM
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Container Responsibility for CMR Foreign Keys


Key generation commands in 3.2.1 are different from those in 3.2.2. In 
3.2.2 you should have <auto-increment/> for generated fields.

Could check whether key generation work for you w/o mapping foreign key 
fields to the primary key fields?

Hanson, Matthew wrote:

> Hi
> 
> Just another FYI on the null primary key for auto-increment primary key
> problem in jboss-3.2.2.  Basically, the auto-increment keys don't seem to
> generate, and I get a null primary key error on creation.  The suggestion
> was to add <auto-increment/> to jbosscmp-jdbc.xml for the key fields.  I
did
> that, and the failure still occurs.  Just to be sure, I simply deployed
the
> jar to 3.2.1.  With 3.2.1, the deployment failed with the following error:
> 
> 2003-12-04 13:50:16,738 ERROR
> [org.jboss.deployment.scanner.URLDeploymentScanner] MBeanException:
> Exception in MBean operation 'checkIncompleteDeployments()'
> Cause: Incomplete Deployment listing:
> Packages waiting for a deployer:
>   <none>
> Incompletely deployed packages:
>   <none>
> MBeans waiting for classes:
>   <none>
> MBeans waiting for other MBeans:
> [ObjectName:
> jboss.j2ee:jndiName=homebrew/ejb/entity/accountHolderBean,service=EJB
>  state: FAILED
>  I Depend On: 
>  Depends On Me: java.lang.IllegalStateException: auto-increment template
not
> found]
> 
> So, in 3.2.1, I removed the <auto-increment/> tag from the beans, and the
> app deploys and the bean works (i.e., auto-increment keys are generated
> properly).
> 
> Can you tell me why the auto-increment tag was suggested for 3.2.2?  Are
> there additional tags that must be included?
> 
> 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

Reply via email to