I am trying to create the AccountRecipeBean (n-side), CMR with accountHolder (1-side).
Here is the bean config for ejb-jar.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar > <description><![CDATA[No Description.]]></description> <display-name>Generated by XDoclet</display-name> <enterprise-beans> <!-- Session Beans --> <session > <description><![CDATA[]]></description> <display-name>Local interface to account information</display-name> <ejb-name>accountFacade</ejb-name> <home>homebrew.ejb.interfaces.accountFacadeHome</home> <remote>homebrew.ejb.interfaces.accountFacade</remote> <ejb-class>homebrew.ejb.session.accountFacadeBean</ejb-class> <session-type>Stateful</session-type> <transaction-type>Container</transaction-type> <ejb-ref > <ejb-ref-name>ejb/accountHolderBean</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>homebrew.ejb.interfaces.accountHolderBeanHome</home> <remote>homebrew.ejb.interfaces.accountHolderBean</remote> <ejb-link>accountHolderBean</ejb-link> </ejb-ref> </session> <!-- To add session beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called session-beans.xml that contains the <session></session> markup for those beans. --> <!-- Entity Beans --> <entity > <description><![CDATA[]]></description> <display-name>Account recipes</display-name> <ejb-name>AccountRecipeBean</ejb-name> <local-home>homebrew.ejb.interfaces.AccountRecipeBeanLocalHome</local-home> <local>homebrew.ejb.interfaces.AccountRecipeBeanLocal</local> <ejb-class>homebrew.ejb.entity.AccountRecipeBeanCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>homebrew.ejb.interfaces.AccountRecipeBeanPK</prim-key-class> <reentrant>true</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>recipe</abstract-schema-name> <cmp-field > <description><![CDATA[]]></description> <field-name>recipeId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>accountId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>recipeName</field-name> </cmp-field> <!-- Write a file named ejb-finders-AccountRecipeBean.xml if you want to define extra finders. --> </entity> <entity > <description><![CDATA[]]></description> <display-name>Recipe hops</display-name> <ejb-name>RecipeHopsBean</ejb-name> <local-home>homebrew.ejb.interfaces.RecipeHopsBeanLocalHome</local-home> <local>homebrew.ejb.interfaces.RecipeHopsBeanLocal</local> <ejb-class>homebrew.ejb.entity.RecipeHopsBeanCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>homebrew.ejb.interfaces.RecipeHopsBeanPK</prim-key-class> <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>recipe_hops</abstract-schema-name> <cmp-field > <description><![CDATA[]]></description> <field-name>recipeHopId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>recipeId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>hopsRefId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>hopForm</field-name> </cmp-field> <!-- Write a file named ejb-finders-RecipeHopsBean.xml if you want to define extra finders. --> </entity> <entity > <description><![CDATA[]]></description> <display-name>General account address information</display-name> <ejb-name>accountAddressBean</ejb-name> <local-home>homebrew.ejb.interfaces.accountAddressBeanLocalHome</local-home> <local>homebrew.ejb.interfaces.accountAddressBeanLocal</local> <ejb-class>homebrew.ejb.entity.accountAddressBeanCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>homebrew.ejb.interfaces.accountAddressBeanPK</prim-key-class > <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>account_address</abstract-schema-name> <cmp-field > <description><![CDATA[]]></description> <field-name>accountId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>addressType</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>streetNumber</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>streetName</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>streetSuffix</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>city</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>state</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>zipCode</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>zip4</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>primaryAddress</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>billingAddress</field-name> </cmp-field> <!-- Write a file named ejb-finders-accountAddressBean.xml if you want to define extra finders. --> </entity> <entity > <description><![CDATA[]]></description> <display-name>General account information</display-name> <ejb-name>accountHolderBean</ejb-name> <local-home>homebrew.ejb.interfaces.accountHolderBeanLocalHome</local-home> <local>homebrew.ejb.interfaces.accountHolderBeanLocal</local> <ejb-class>homebrew.ejb.entity.accountHolderBeanCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>homebrew.ejb.interfaces.accountHolderBeanPK</prim-key-class> <reentrant>true</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>account</abstract-schema-name> <cmp-field > <description><![CDATA[]]></description> <field-name>accountId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>accountRoleId</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>emailAddress</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>emailTypeCd</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>accountPassword</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>firstName</field-name> </cmp-field> <cmp-field > <description><![CDATA[]]></description> <field-name>SSN</field-name> </cmp-field> <query> <query-method> <method-name>findByEmailAddress</method-name> <method-params> <method-param>java.lang.String</method-param> </method-params> </query-method> <ejb-ql><![CDATA[SELECT OBJECT(a) FROM account AS a WHERE a.emailAddress = ?1]]></ejb-ql> </query> <!-- Write a file named ejb-finders-accountHolderBean.xml if you want to define extra finders. --> </entity> <!-- To add entity beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called entity-beans.xml that contains the <entity></entity> markup for those beans. --> <!-- Message Driven Beans --> <!-- To add message driven beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called message-driven-beans.xml that contains the <message-driven></message-driven> markup for those beans. --> </enterprise-beans> <!-- Relationships --> <relationships > <ejb-relation > <ejb-relation-name>Account-Recipe</ejb-relation-name> <ejb-relationship-role > <ejb-relationship-role-name>Recipe-Belongs-To-Account</ejb-relationship-role -name> <multiplicity>Many</multiplicity> <relationship-role-source > <ejb-name>AccountRecipeBean</ejb-name> </relationship-role-source> <cmr-field > <cmr-field-name>accountHolder</cmr-field-name> </cmr-field> </ejb-relationship-role> <ejb-relationship-role > <ejb-relationship-role-name>Account-Has-Recipes</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source > <ejb-name>accountHolderBean</ejb-name> </relationship-role-source> <cmr-field > <cmr-field-name>recipes</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> </ejb-relation> <ejb-relation > <ejb-relation-name>Recipe-Hops</ejb-relation-name> <ejb-relationship-role > <ejb-relationship-role-name>Recipe-Has-Hops</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source > <ejb-name>AccountRecipeBean</ejb-name> </relationship-role-source> <cmr-field > <cmr-field-name>recipeHops</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relationship-role > <ejb-relationship-role-name>Hops-Belongs-To-Recipe</ejb-relationship-role-na me> <multiplicity>Many</multiplicity> <relationship-role-source > <ejb-name>RecipeHopsBean</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation> <ejb-relation > <ejb-relation-name>Account-Address</ejb-relation-name> <ejb-relationship-role > <ejb-relationship-role-name>Account-Has-Addresses</ejb-relationship-role-nam e> <multiplicity>One</multiplicity> <relationship-role-source > <ejb-name>accountHolderBean</ejb-name> </relationship-role-source> <cmr-field > <cmr-field-name>addresses</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relationship-role > <ejb-relationship-role-name>Address-Belongs-To-Account</ejb-relationship-rol e-name> <multiplicity>Many</multiplicity> <relationship-role-source > <ejb-name>accountAddressBean</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation> </relationships> <!-- Assembly Descriptor --> <assembly-descriptor > <!-- To add additional assembly descriptor info here, add a file to your XDoclet merge directory called assembly-descriptor.xml that contains the <assembly-descriptor></assembly-descriptor> markup. --> <!-- finder permissions --> <!-- finder permissions --> <!-- finder permissions --> <!-- finder permissions --> <!-- finder permissions --> <!-- transactions --> <container-transaction > <method > <ejb-name>AccountRecipeBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> <container-transaction > <method > <ejb-name>RecipeHopsBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> <container-transaction > <method > <ejb-name>accountAddressBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> <container-transaction > <method > <ejb-name>accountHolderBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> <!-- finder transactions --> </assembly-descriptor> </ejb-jar> Here is jbosscmp-jdbc.xml: <?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>AccountRecipeBean</ejb-name> <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> <entity-command name="hsqldb-fetch-key"> </entity-command> <!-- jboss 3.2 features --> <!-- optimistic locking does not express the exclusions needed --> </entity> <entity> <ejb-name>RecipeHopsBean</ejb-name> <datasource>java:/DefaultDS</datasource> <datasource-mapping>Hypersonic SQL</datasource-mapping> <table-name>recipe_hops</table-name> <cmp-field> <field-name>recipeHopId</field-name> <column-name>recipe_hop_id</column-name> </cmp-field> <cmp-field> <field-name>recipeId</field-name> <column-name>recipe_id</column-name> </cmp-field> <cmp-field> <field-name>hopsRefId</field-name> <column-name>ref_recipe_hops_id</column-name> </cmp-field> <cmp-field> <field-name>hopForm</field-name> <column-name>hop_form</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> <entity> <ejb-name>accountAddressBean</ejb-name> <table-name>account_address</table-name> <cmp-field> <field-name>accountId</field-name> <column-name>account_id</column-name> </cmp-field> <cmp-field> <field-name>addressType</field-name> <column-name>address_type</column-name> </cmp-field> <cmp-field> <field-name>streetNumber</field-name> <column-name>str_num</column-name> </cmp-field> <cmp-field> <field-name>streetName</field-name> <column-name>str_name</column-name> </cmp-field> <cmp-field> <field-name>streetSuffix</field-name> <column-name>str_suffix</column-name> </cmp-field> <cmp-field> <field-name>city</field-name> <column-name>city</column-name> </cmp-field> <cmp-field> <field-name>state</field-name> <column-name>state</column-name> </cmp-field> <cmp-field> <field-name>zipCode</field-name> <column-name>zip</column-name> </cmp-field> <cmp-field> <field-name>zip4</field-name> <column-name>zip4</column-name> </cmp-field> <cmp-field> <field-name>primaryAddress</field-name> <column-name>primary_address</column-name> </cmp-field> <cmp-field> <field-name>billingAddress</field-name> <column-name>billing_address</column-name> </cmp-field> <!-- jboss 3.2 features --> <!-- optimistic locking does not express the exclusions needed --> </entity> <entity> <ejb-name>accountHolderBean</ejb-name> <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> </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> <relationships> <ejb-relation> <ejb-relation-name>Account-Recipe</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>Recipe-Belongs-To-Account</ejb-relationship-role -name> <key-fields/> </ejb-relationship-role> <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-relation> <ejb-relation> <ejb-relation-name>Recipe-Hops</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>Recipe-Has-Hops</ejb-relationship-role-name> <key-fields> <key-field> <field-name>recipeId</field-name> <column-name>recipe_id</column-name> </key-field> </key-fields> </ejb-relationship-role> <ejb-relationship-role> <ejb-relationship-role-name>Hops-Belongs-To-Recipe</ejb-relationship-role-na me> <key-fields/> </ejb-relationship-role> </ejb-relation> <ejb-relation> <ejb-relation-name>Account-Address</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>Account-Has-Addresses</ejb-relationship-role-nam e> <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>Address-Belongs-To-Account</ejb-relationship-rol e-name> <key-fields/> </ejb-relationship-role> </ejb-relation> </relationships> </jbosscmp-jdbc> Any advice? Thanks!!! Regards, Matt Hanson -----Original Message----- From: Alexey Loubyansky [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 03, 2003 9:51 AM To: [EMAIL PROTECTED] Subject: Re: [JBoss-user] Container Responsibility for CMR Foreign Keys How the beans is configured in ejb-jar.xml and jbosscmp-jdbc.xml? Hanson, Matthew wrote: > Hi, > > I have modified the reentrancy tags for my beans to false, deployed the > beans to binary download of Jboss 3.2.2 with insert-after-ejb-post-create, > and now I catch the following exception in ejbCreate of the n-side bean: > > 2003-12-03 09:15:53,858 ERROR [org.jboss.ejb.plugins.LogInterceptor] > TransactionRolledbackLocalException in method: public abstract void > homebrew.ejb.interfaces.accountHolderBeanLocal.setaccountHolderBeanValue(hom > ebrew.ejb.interfaces.accountHolderBeanValue), causedBy: > javax.ejb.CreateException: Primary key for created instance is null. > at > org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManage > r.java:520) > at > org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManag > er.java:208) > at > org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntit > y(CachedConnectionInterceptor.java:269) > at > org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:580) > 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) > > Is the <entity-command name="hsqldb-fetch-key"> for the bean is being > ignored in Jboss 3.2.2? > > Please advise! Thanks! > > Regards, > Matt Hanson > > -----Original Message----- > From: Alexey Loubyansky [mailto:[EMAIL PROTECTED] > Sent: Tuesday, December 02, 2003 3:27 PM > To: [EMAIL PROTECTED] > Subject: Re: [JBoss-user] Container Responsibility for CMR Foreign Keys > > > By the spec, you may not establish relationships in ejbCreate but may in > ejbPostCreate. > By default, INSERT is done after ejbCreate but before ejbPostCreate. > You can use insert-after-ejb-post-create to delay INSERT until after > ejbPostCreate but this feature is available, AFAIR, since 3.2.2. > > Hanson, Matthew wrote: > > >>Hi, >> >>I am using xdoclet 1.2b2 to generate deployment descriptors and classes, >>including value objects, for two beans that I hope to write with support > > for > >>CMR. We also use Jboss 3.2.1 as my app server and hypersonic and/or mysql >>as the db. >> >>Basically, I just want to write a relatively "ejb-standard" foreign keyed >>insert for 1:n-related beans that are both being creating together. >> >>The bean class generated by xdoclet maintains vectors of added, removed, > > and > >>updated value objects of the type that is the n-side of the 1:n > > relationship > >>that I hope to support. It also generates a set...BeanValue() method to >>process the 1-side bean value object. This set...BeanValue() methods >>iterates across the n-side value objects and tries to create the n-siders >>via the create followed by Collection.add methods. The keys on the > > 1-side, > >>however, are not included in the value object, and the create fails the >>non-null foreign key constraint. >> >>Before posting to xdoclet, I stepped back and started to think that the > > ejb > >>container (Jboss) should probably creating and assigning foreign keys to > > the > >>n-side with the local interface set methods. The ejb spec, however, does >>not seem to support this thought, and I do see posts on the jboss site > > that > >>say the setting of foreign keys of the n-side is generally done in the >>ejbPostCreate method of the 1-side. Well, I tried that, and I can output >>the n-side value objects in the 1-side ejbPostCreate and see the updated > > key > >>field, but the insert on the n-side still fails!?!?!?!?. >> >>Now, I also see in the posts that Jboss 3.2.2 may offer a new tag >><insert-after-ejb-post-create> in standardjboss.xml that prompts the app >>server to wait until after ejbPostCreate to try to write the n-side of the >>datasource. >> >>Before I spend another day on this, I am wondering if someone can just > > tell > >>me: >>(1) Are these keyed inserts on related beans even possible? >>(2) What is the recommended way to do them? (Code, new jboss version, >>other?) >> >>Wow - I hope that I am making some sense, because it seems like a very >>common thing to do... >> >>Any help would be great! >> >>Regards, >>Matt Hanson >> >> >>------------------------------------------------------- >>This SF.net email is sponsored by OSDN's Audience Survey. >>Help shape OSDN's sites and tell us what you think. Take this >>five minute survey and you could win a $250 Gift Certificate. >>http://www.wrgsurveys.com/2003/osdntech03.php?site=8 >>_______________________________________________ >>JBoss-user mailing list >>[EMAIL PROTECTED] >>https://lists.sourceforge.net/lists/listinfo/jboss-user >> >> > > > > > ------------------------------------------------------- > This SF.net email is sponsored by OSDN's Audience Survey. > Help shape OSDN's sites and tell us what you think. Take this > five minute survey and you could win a $250 Gift Certificate. > http://www.wrgsurveys.com/2003/osdntech03.php?site=8 > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > > > ------------------------------------------------------- > This SF.net email is sponsored by OSDN's Audience Survey. > Help shape OSDN's sites and tell us what you think. Take this > five minute survey and you could win a $250 Gift Certificate. > http://www.wrgsurveys.com/2003/osdntech03.php?site=8 > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > > ------------------------------------------------------- This SF.net email is sponsored by OSDN's Audience Survey. Help shape OSDN's sites and tell us what you think. Take this five minute survey and you could win a $250 Gift Certificate. http://www.wrgsurveys.com/2003/osdntech03.php?site=8 _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user ------------------------------------------------------- This SF.net email is sponsored by OSDN's Audience Survey. Help shape OSDN's sites and tell us what you think. Take this five minute survey and you could win a $250 Gift Certificate. http://www.wrgsurveys.com/2003/osdntech03.php?site=8 _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user