Re: [JBoss-user] CMR create fails for many side
Hello Matthew, you defined two primary keys for each entity: one is unknown and the other one is "known". You can't do it. Get rid of one of them. To let the "known" key be generated just mark it as auto-increment. Note, entity-command declaration is needed in both cases. alex Monday, August 11, 2003, 9:14:39 PM, Matthew Hanson wrote: > 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): > > accountHolderBean > java:/DefaultDS > Hypersonic SQL > account > > accountId > account_id > > > accountRoleId > account_role_id > . > . > . > > java.lang.Integer > account_id > INTEGER > INTEGER > > > class="org.jboss.ejb.plugins.cmp.jdbc.hsqldb.JDBCHsqldbCreateCommand"> > > > > > However, the following entries for the many side, using the same basic tags, > fails to write successfully: > > AccountRecipeBean > java:/DefaultDS > Hypersonic SQL > recipe > > recipeId > recipe_id > > > accountId > account_id > > > recipeName > recipe_name > > > java.lang.Integer > recipe_id > INTEGER > INTEGER > > > class="org.jboss.ejb.plugins.cmp.jdbc.hsqldb.JDBCHsqldbCreateCommand"> > > > > > Here is the relationship definition: > > Account-Recipe > > Account-Has-Recipes > > >accountId >account_id > > > > > Recipe-Belongs-To-Account> > > > > 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.(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:
[JBoss-user] CMR create fails for many side
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): accountHolderBean java:/DefaultDS Hypersonic SQL account accountId account_id accountRoleId account_role_id . . . java.lang.Integer account_id INTEGER INTEGER However, the following entries for the many side, using the same basic tags, fails to write successfully: AccountRecipeBean java:/DefaultDS Hypersonic SQL recipe recipeId recipe_id accountId account_id recipeName recipe_name java.lang.Integer recipe_id INTEGER INTEGER Here is the relationship definition: Account-Recipe Account-Has-Recipes accountId account_id Recipe-Belongs-To-Account 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.(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