Hi,

jboss 3.2.1 CMP2.0 with integrated hsqldb and code generation by xdoclet
1.2b3-dev

I am having some trouble writing a many side entity bean within CMR to my
datasource (hsqldb).  I use xdoclet to generate much of the source and
deployment descriptors.  I am able to create the one side, which has a
single column, auto increment type primary key, using the following
deployment tags (jbosscmp-jdbc.xml):

      <entity>
         <ejb-name>accountHolderBean</ejb-name>
                 <datasource>java:/DefaultDS</datasource>
                 <datasource-mapping>Hypersonic SQL</datasource-mapping>
         <table-name>account</table-name>

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

        </cmp-field>
         <cmp-field>
            <field-name>accountRoleId</field-name>
            <column-name>account_role_id</column-name>
.
.
.

        <unknown-pk>
                <unknown-pk-class>java.lang.Integer</unknown-pk-class>
                <column-name>account_id</column-name>
                <jdbc-type>INTEGER</jdbc-type>
                <sql-type>INTEGER</sql-type>
                <auto-increment/>
        </unknown-pk>
        <entity-command name="account_id_pk"
class="org.jboss.ejb.plugins.cmp.jdbc.hsqldb.JDBCHsqldbCreateCommand">
        </entity-command>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
      </entity>

However, the following entries for the many side, using the same basic tags,
fails to write successfully:

      <entity>
         <ejb-name>AccountRecipeBean</ejb-name>
                 <datasource>java:/DefaultDS</datasource>
                 <datasource-mapping>Hypersonic SQL</datasource-mapping>
         <table-name>recipe</table-name>

         <cmp-field>
            <field-name>recipeId</field-name>
            <column-name>recipe_id</column-name>

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

        </cmp-field>
         <cmp-field>
            <field-name>recipeName</field-name>
            <column-name>recipe_name</column-name>

        </cmp-field>

        <unknown-pk>
                <unknown-pk-class>java.lang.Integer</unknown-pk-class>
                <column-name>recipe_id</column-name>
                <jdbc-type>INTEGER</jdbc-type>
                <sql-type>INTEGER</sql-type>
                <auto-increment/>
        </unknown-pk>
        <entity-command name="recipe_id_pk"
class="org.jboss.ejb.plugins.cmp.jdbc.hsqldb.JDBCHsqldbCreateCommand">
        </entity-command>
<!-- jboss 3.2 features -->
<!-- optimistic locking does not express the exclusions needed -->
      </entity>

Here is the relationship definition:

    <ejb-relation>
      <ejb-relation-name>Account-Recipe</ejb-relation-name>

      <ejb-relationship-role>
 
<ejb-relationship-role-name>Account-Has-Recipes</ejb-relationship-role-name>
          <key-fields>
             <key-field>
               <field-name>accountId</field-name>
               <column-name>account_id</column-name>
             </key-field>
          </key-fields>

      </ejb-relationship-role>
      <ejb-relationship-role>
 
<ejb-relationship-role-name>Recipe-Belongs-To-Account</ejb-relationship-role
-name>
                  <key-fields/>

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

The client uses an xdoclet value object for the many side, with a two-column
primary key that includes the one-side key and a similar, auto-increment
primary key of its own.  I have tried several combinations of the primary
key passed into the facade to create the many side (null pk instance, actual
pk object w/only the one-side value populated, actual pk object w/one-side
and dummy many side key value, such as 10, populated).  In all cases, the
following stack trace is generated (in this case, the many-side key is just
a null Integer):

13:03:07,888 INFO  [STDOUT] add recipe:  {recipeId=null accountId=9
recipeName=Pale Ale}
13:03:07,898 INFO  [STDOUT] in recipe bean ejbCreate for value object...
13:03:07,898 ERROR [AccountRecipeBean] Could not create entity
java.sql.SQLException: Try to insert null into a non-nullable column in
statement [INSERT INTO RECIP
E (recipe_name) VALUES ('Pale Ale')]
        at org.hsqldb.Trace.getError(Unknown Source)
        at org.hsqldb.Result.<init>(Unknown Source)
        at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
        at org.hsqldb.jdbcConnection.execute(Unknown Source)
        at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
        at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
        at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
        at
org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(Wrapp
edPreparedSta
tement.java:308)
        at
org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.insertEntity(
JDBCAbstractV
endorCreateCommand.java:118)
        at
org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.execute(JDBCA
bstractVendor
CreateCommand.java:76)
        at
org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManage
r.java:569)
        at
org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManag
er.java:225)
        at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntit
y(CachedConne
ctionInterceptor.java:270)
        at
org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:571)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContaine
r.java:998)
        at
org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.jav
a:88)
        at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySync
hronizationIn
terceptor.java:188)
        at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(
CachedConnect
ionInterceptor.java:215)
        at
org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.jav
a:88)
        at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInt
erceptor.java
:91)
        at
org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor
.java:61)
        at
org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInt
erceptor.java
:28)
        at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor
.java:88)
        at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.
java:243)
        at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
        at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.jav
a:92)
        at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
        at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryF
inderIntercep
tor.java:93)
        at
org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
        at org.jboss.ejb.Container.invoke(Container.java:694)
        at
org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyF
actory.java:2
72)
        at
org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
        at $Proxy90.create(Unknown Source)
        at
homebrew.ejb.session.accountFacadeBean.addRecipes(accountFacadeBean.java:342
)
        at
homebrew.ejb.session.accountFacadeBean.setAccountHolder(accountFacadeBean.ja
va:186)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulS
essionContain
er.java:878)
        at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:11
7)
        at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(Cach
edConnectionI
nterceptor.java:186)

The client fills an array of many side value object, and the one side facade
basically does this:

        protected void addRecipes(Collection addedRecipes)
        throws NamingException, CreateException
        {
                Iterator addrIt = addedRecipes.iterator();
                AccountRecipeBeanLocal loc = null;
                System.out.println("trying to add recipe(s)...");
                while(addrIt.hasNext())
                {
                        AccountRecipeBeanValue val =
(AccountRecipeBeanValue) addrIt.next();
                        System.out.println("add recipe:  " +
val.toString());
                        loc =
AccountRecipeBeanUtil.getLocalHome().create(val);
                }
        }

I have looked at some of the code from jboss source, but I thought I would
see if anyone sees any big problems with the deployment descriptor info or
the client many-side primary key vals.

If anyone can help me solve this problem, I would appreciate it very much.

Regards,
Matt Hanson


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to