Ejbgen: bug in many-to-many cmp

I am trying to use ejbgen to generate the code for many-to-many cmr relationships.
I have come across a bug where the ejb-jar.xml generates a non compliant ejb2.0 xml tag. The actual tag should be
<relationship-role-source> however, it generates <role-source>.

Saurabh Gupta <[email protected]> wrote in
news:[email protected]:
I am trying to use ejbgen to generate the code for many-to-many cmr
relationships.
I have come across a bug where the ejb-jar.xml generates a non
compliant ejb2.0 xml tag. The actual tag should be
<relationship-role-source> however, it generates <role-source>. Can you post (or email me) your two sources?
Thanks.
Cedric
http://beust.com/weblog

Similar Messages

  • Plea for example - Many-to-Many CMP EJB

    I am attempting to create an EJB that uses Container Managed Persistence,
    but my situation seems to be an odd one. The EJB needs to have a
    Many-to-Many relationship to itself, because the object is Hierarchical.
    Because this is my first EJB I am having a hard time with all of the
    deployment descriptors.
    I am asking for an example of any Many-to-Many EJB relationship that uses
    Weblogic's built-in link table creation to make the relationship (that
    works). I realize that there are confidentiality issues with many people
    releasing code. I will make any promise (short of selling my soul) that the
    code will be safe and promply destroyed immediately after inspection.
    Thanks for any help,
    Tom
    [email protected]

    The following describes how to establish a self many-to-many relationship with regards to Product having many parent products and many children products. I have attached the example files as well. Most of these files were generated using EJBGen. I would highly recommend it...
    EJB
    v Navigating from a Product to its parent Products results in getParents() method in Product
    § Since a Product can have many parents the return type of getParents() method is
    java.util.Collection
    § Calling setParents() method results in establishing the new links between this Parent and
    parent Products
    § Adding a Product as Parent to the Product results in establishing a new link between this
    Product and other Product as parent
    · This product is made available in the collection of children in the other Product
    § Removing a Product as Parent to the Product results in breaking a link between this
    Product and the other Product as parent
    · This product is also removed from the collection of children in the other Product
    v Navigating from a Product to its children Products results in getChildren() method in Product
    § Since a Product can have many children the return type of getChildren() method is
    java.util.Collection
    § Calling setChildren() method results in breaking the old links between this Product and
    children Products
    § Adding a Product as child to the Product results in establishing a new link between this
    Product and other Product as child
    · This product is made available in the collection of parents in the other Product
    § Removing a Product as child from the Product results in breaking a link between this
    Product and the other Product as child
    · This Product is also removed from the collection of parents in the other Product.
    v Example: ProductBean
    Ø DataBase
    v For a many-to-many relationship define a new associative (join) table
    v Define a new Parent_Child_Product associative table
    v The Parent_Child_Product has compound primary keys: Parent_Product_ID and
    Child_Product_ID
    v Parent_Product_ID and Child_Product_ID are foreign keys to Product table
    v Example: Product, Parent_Child_Product
    Ø Deployment Descriptors
    v ejb-jar.xml
    § Within <ejb-jar>.<relationships>.<ejb-relation> define the following:
    · Name of the relationship
    o Example: <ejb-relation-name>Parent-Product-Children</ejb-relation-name>
    · Role from the parent Product side
    o Source
    § Example:
    <relationship-role-source>
    <ejb-name>Product</ejb-name>
    </relationship-role-source>
    o Role name
    § Example: <ejb-relationship-role-name>many-Product@children-Have-Product</
    ejb-relationship-role-name>
    o Multiplicity
    § Example: <multiplicity>many</multiplicity>
    o CMR field
    § Example:
    <cmr-field>
    <cmr-field-name>children</cmr-field-name>
    <cmr-field-type>java.util.Collection</cmr-field-type>
    </cmr-field>
    · Role from the child Product side
    o Source
    § Example:
    <relationship-role-source>
    <ejb-name>Product</ejb-name>
    </relationship-role-source>
    o Role name
    § Example: <ejb-relationship-role-name>many-Product@parents-Have-Product</
    ejb-relationship-role-name>
    o Multiplicity
    § Example: <multiplicity>many</multiplicity>
    o CMR field
    § Example:
    <cmr-field>
    <cmr-field-name>parents</cmr-field-name>
    <cmr-field-type>java.util.Collection</cmr-field-type>
    </cmr-field>
    v weblogic-ejb-jar.xml
    v weblogic-cmp-rdbms-jar.xml
    § Within <weblogic-rdbms-jar>.<weblogic-rdbms-relation> specify the following:.23
    · Name of the relationship matching the name in ejb-jar
    o Example: <ejb-relation-name> Parent-Product-Children</ejb-relation-name>
    · Specify the name of the joint table
    o Example: <table-name> Parent_Child_Product</table-name>
    · Specify the mapping using <weblogic-relationship-role>
    o Specify the role name matching the name in the ejb-jar
    § Example: <relationship-role-name>many-Product@children-Have-Product</
    relationship-role-name>
    o Define <relationship-role-map> that defines the mapping of the foreign key to
    the primary key mapping
    § Example:
    <relationship-role-map>
    <column-map>
    <foreign-key-column>Parent_Product_ID</foreign-key-column>
    <key-column>Product_ID</key-column>
    </column-map>
    </relationship-role-map>
    · Specify the mapping using <weblogic-relationship-role>
    o Specify the role name matching the name in the ejb-jar
    § Example: <relationship-role-name> many-Product@parents-Have-Product</
    relationship-role-name>
    o Define <relationship-role-map> that defines the mapping of the foreign key to
    the primary key mapping
    § Example:
    <relationship-role-map>
    <column-map>
    <foreign-key-column>Child_Product_ID</foreign-key-column>
    <key-column>Product_ID</key-column>
    </column-map>
    </relationship-role-map>
    "Thomas A. Valletta" <[email protected]> wrote in message news:[email protected]...
    I am attempting to create an EJB that uses Container Managed Persistence,
    but my situation seems to be an odd one. The EJB needs to have a
    Many-to-Many relationship to itself, because the object is Hierarchical.
    Because this is my first EJB I am having a hard time with all of the
    deployment descriptors.
    I am asking for an example of any Many-to-Many EJB relationship that uses
    Weblogic's built-in link table creation to make the relationship (that
    works). I realize that there are confidentiality issues with many people
    releasing code. I will make any promise (short of selling my soul) that the
    code will be safe and promply destroyed immediately after inspection.
    Thanks for any help,
    Tom
    [email protected]
    [att1.html]
    [ejb-jar.xml]
    [weblogic-cmp-rdbms-jar.xml]
    [weblogic-ejb-jar.xml]
    [ProductBean.java]
    [ProductLocal.java]
    [ProductLocalHome.java]

  • Defining a many-to-many relationship with CMP EJBs  : does it work for you

    Curious to know whether someone has been able to set up a many to many relationship between two entity beans.
    I have been struggling with this for days now and I can't get it to work.
    In my test project I have two entity beans, resp. Consultant and Solution.
    Consultant has a cmr field called 'solutions', which is a collection object from the opposite side (Solution).
    This is the source of the ejb-jar.xml file
    <?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>EJB JAR description</description>
         <display-name>EJB JAR</display-name>
         <enterprise-beans>
              <session>
                   <ejb-name>ProfilerBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbses.profiling.Profiler</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerBean</ejb-class>
                   <session-type>Stateless</session-type>
                   <transaction-type>Container</transaction-type>
                   <ejb-local-ref>
                        <ejb-ref-name>EJBTesting/Solution</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocalHome</local-home>
                        <local>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocal</local>
                        <ejb-link>SolutionBean</ejb-link>
                   </ejb-local-ref>
                   <ejb-local-ref>
                        <ejb-ref-name>EJBTesting/Consultant</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocalHome</local-home>
                        <local>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocal</local>
                        <ejb-link>ConsultantBean</ejb-link>
                   </ejb-local-ref>
              </session>
              <entity>
                   <ejb-name>ConsultantBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbcmp.profiling.Consultant</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Consultant</abstract-schema-name>
                   <cmp-field>
                        <field-name>firstname</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>lastname</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>country</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>id</field-name>
                   </cmp-field>
                   <primkey-field>id</primkey-field>
                   <query>
                        <query-method>
                             <method-name>findBySolution</method-name>
                             <method-params>
                                  <method-param>java.lang.String</method-param>
                             </method-params>
                        </query-method>
                        <ejb-ql>SELECT Object(c) FROM Consultant AS c,
                        IN(c.solutions) s WHERE s.id = ?1 </ejb-ql>
                   </query>
              </entity>
              <entity>
                   <ejb-name>SolutionBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbcmp.profiling.Solution</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Solution</abstract-schema-name>
                   <cmp-field>
                        <field-name>description</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>name</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>parent</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>id</field-name>
                   </cmp-field>
                   <primkey-field>id</primkey-field>
                   <query>
                        <query-method>
                             <method-name>findChildSolutions</method-name>
                             <method-params>
                                  <method-param>java.lang.String</method-param>
                             </method-params>
                        </query-method>
                        <ejb-ql>SELECT Object(s) FROM Solution AS s WHERE
                        s.parent = ?1</ejb-ql>
                   </query>
                   <query>
                        <query-method>
                             <method-name>findTopLevelSolutions</method-name>
                             <method-params/>
                        </query-method>
                        <ejb-ql>Select Object(s) FROM Solution AS s WHERE
                        (s.parent = &apos;none&apos;)</ejb-ql>
                   </query>
              </entity>
         </enterprise-beans>
         <relationships>
              <ejb-relation>
                   <description>A consultant may have one or more areas of expertise</description>
                   <ejb-relation-name>Consultant_Solutions</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantBean</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <relationship-role-source>
                             <ejb-name>ConsultantBean</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>solutions</cmr-field-name>
                             <cmr-field-type>java.util.Collection</cmr-field-type>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionBean</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <relationship-role-source>
                             <ejb-name>SolutionBean</ejb-name>
                        </relationship-role-source>
                   </ejb-relationship-role>
              </ejb-relation>
         </relationships>
         <assembly-descriptor>
              <container-transaction>
                   <description>container-transaction</description>
                   <method>
                        <ejb-name>SolutionBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>ProfilerBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>ConsultantBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <trans-attribute>Required</trans-attribute>
              </container-transaction>
         </assembly-descriptor>
    </ejb-jar>
    I created a stateless session bean as a business facade for the two entity beans. I then created a webservice to test the beans.
    What works :
    - create a consultant
    - get a consultant
    - create a solution
    - get a solution
    (basically everything that doesn't involve the relationship field.
    However, what doesn't work is the method call assignSolution:
    - assign solution : this is implemented as follows
    Business Method.
         public void assignSolution(String consultantID, String solutionID)
              throws ProfilingException {
              // TODO : Implement
              ConsultantLocal cons = null;
              SolutionLocal sol = null;
              try {
                   cons = consHome.findByPrimaryKey(consultantID);
                   sol = solHome.findByPrimaryKey(solutionID);
                   Collection solutions = cons.getSolutions();
                   solutions.add(sol);
                   //sol.getConsultants().add(cons);
              } catch (FinderException ex) {
                   ex.printStackTrace();
                   throw new ProfilingException("failed to retrieve data from DB", ex);
    As you can see I am trying to use the CM Relationship in this methhod. Adding the solution to a consultant should be as simple as adding a solution object to the collection retrieved with the getSolutions accessor. The Container is expected to persist the information in my MAXDB database.
    However this doesn't happen.
    The ORM details as defined in the persistent.xml follows :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE persistent-ejb-map SYSTEM "persistent.dtd">
    <persistent-ejb-map>
         <locking
              type="Table"/>
         <db-properties>
              <data-source-name>TCC_PORTAL_PROFILER</data-source-name>
              <database-vendor
                   name="SAPDB"/>
         </db-properties>
         <entity-beans>
              <entity-bean>
                   <ejb-name>ConsultantBean</ejb-name>
                   <table-name>PFL_CONSULTANTS</table-name>
                   <field-map
                        key-type="NoKey">
                        <field-name>firstname</field-name>
                        <column>
                             <column-name>FIRSTNAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>lastname</field-name>
                        <column>
                             <column-name>LASTNAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>country</field-name>
                        <column>
                             <column-name>COUNTRY</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="PrimaryKey">
                        <field-name>id</field-name>
                        <column>
                             <column-name>ID</column-name>
                        </column>
                   </field-map>
                   <finder-descriptor>
                        <method-name>findBySolution</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
              </entity-bean>
              <entity-bean>
                   <ejb-name>SolutionBean</ejb-name>
                   <table-name>PFL_SAPSOLUTIONS</table-name>
                   <field-map
                        key-type="NoKey">
                        <field-name>description</field-name>
                        <column>
                             <column-name>DESCRIPTION</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>name</field-name>
                        <column>
                             <column-name>NAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>parent</field-name>
                        <column>
                             <column-name>PARENTID</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="PrimaryKey">
                        <field-name>id</field-name>
                        <column>
                             <column-name>ID</column-name>
                        </column>
                   </field-map>
                   <finder-descriptor>
                        <method-name>findChildSolutions</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
                   <finder-descriptor>
                        <method-name>findTopLevelSolutions</method-name>
                        <method-params/>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
              </entity-bean>
         </entity-beans>
         <relationships>
              <table-relation>
                   <help-table>PFL_CONS_SOL_MAP</help-table>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>ConsultantBean</ejb-name>
                        <cmr-field>solutions</cmr-field>
                        <fk-column>
                             <column-name>CONSULTANTID</column-name>
                             <pk-field-name>id</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>SolutionBean</ejb-name>
                        <fk-column>
                             <column-name>SOLUTIONID</column-name>
                             <pk-field-name>id</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
              </table-relation>
         </relationships>
    </persistent-ejb-map>
    The error in the default trace file when calling the method states, there is an "inconsistency in the number of primary keys". Details follow.
    #1.5#000F1F188E5C004400000000000010480003E76C80EFD57A#1098880364327#com.sap.engine.services.ejb#com.atosorigin.tcc/EJBCMPProfilingTest#com.sap.engine.services.ejb#Guest#2####4d2b2370281411d9a40d000f1f188e5c#SAPEngine_Application_Thread[impl:3]_31##0#0#Error##Java###
    [EXCEPTION]
    #1#com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method assignSolution.
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerObjectImpl0.assignSolution(ProfilerObjectImpl0.java:822)
         at com.atosorigin.tcc.testing.ejbses.profiling.Profiler_Stub.assignSolution(Profiler_Stub.java:533)
         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 com.sap.engine.services.ejb.session.stateless_sp5.ObjectStubProxyImpl.invoke(ObjectStubProxyImpl.java:187)
         at $Proxy73.assignSolution(Unknown Source)
         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 com.sap.engine.services.webservices.runtime.EJBImplementationContainer.invokeMethod(EJBImplementationContainer.java:126)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:146)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:68)
         at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPost(ServletDispatcherImpl.java:92)
         at SoapServlet.doPost(SoapServlet.java:51)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:385)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:263)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:339)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:317)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:810)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:238)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:147)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)
    Caused by: com.sap.engine.services.applocking.exception.SAPAppLockingIllegalArgumentException: Inconsistency in number of primary keys
         at com.sap.engine.services.applocking.TableLockingImpl.getArgument(TableLockingImpl.java:385)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:128)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:138)
         at com.sap.engine.services.ejb.entity.pm.lock.TableLockingSystem.write(TableLockingSystem.java:82)
         at com.sap.engine.services.ejb.entity.pm.PersistentM2M.create(PersistentM2M.java:172)
         at com.sap.engine.services.ejb.entity.pm.PersistentCacheM2M.add(PersistentCacheM2M.java:197)
         at com.sap.engine.services.ejb.entity.pm.multiple.CollectionM2M.add(CollectionM2M.java:57)
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerBean.assignSolution(ProfilerBean.java:201)
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerObjectImpl0.assignSolution(ProfilerObjectImpl0.java:771)
         ... 32 more
    I can't figure out what the problem is with the ORM mapping defined.
    On the database level I have three tables. Consultant maps to PFL_CONSULTANT, Solution to PFL_SAPSOLUTIONS. The third table PFL_CONS_SOL_MAP is the help table used for the relationship (having two fields, which are in fact foreign keys from the other two tables to express the assignment of solutions to consultants (where a consultant can have one or more solutions).
    ps. : I am running Netweaver Developer Workplace (Netweaver 2004, at stack level 5)
    Message was edited by: Theo Paesen

    Hm, after disabling 'automatic locking' it works.

  • Many-To-Many CMP 2.0

    Hi,
    1)With a classic java object model, if we have a M:M relationship, we have to procedd this way Re: Many-to-many mapping question
    but with EJB, I cannot do that without getting a classCastException ; it seems that the example ejb cmp 2.0 relationships given with the toplink installation, we do not need to set the back reference. Then how is this working (Is this because of the bidirectionnal settings, but I thought, --Donald Smith sayed it is not good practise)?
    2)I have build a small example with customer and car ejb cmp 2.0. I add a car to a customer, it works without setting the back reference and without bidirectionnal relationship. But when I call again the instance of this customer after having deleted manually the car added of the relation table, the car does appears on the list of car for this customer which is not normal.
    I need to restart the server to get the normal behavior. Something else, if I add again the car to the csutomer, it adds several additionnal car, not in the database (probably because of the unique constraint) but in the collection of car of the client ejb instance and it does not throws any exception.
    I need some help for this issue.
    Vlad

    Here is the server output for the first add :
    [TopLink]: ServerSession(529044)--Connection(3011271)--SELECT NOM, IDCLIENT FROM CLIENT WHERE (IDCLI
    ENT = 33)
    [TopLink]: ServerSession(529044)--Connection(2942627)--SELECT NOM, IDVOITURE FROM VOITURE WHERE (IDV
    OITURE = 1904952)
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(7479016)--Connection(0)--acquire unit of work:5497685
    [TopLink]: UnitOfWork(5497685)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(2446763)--SELECT t1.NOM, t1.IDVOITURE FROM CLIENT_VOITU
    RE t0, VOITURE t1 WHERE ((t0.IDCLIENT = 33) AND (t1.IDVOITURE = t0.IDVOITURE))
    [TopLink]: UnitOfWork(5497685)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(5497685)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(5497685)--Connection(0)--release unit of work
    [TopLink]: ClientSession(7479016)--Connection(0)--client released
    Avant ajout : Voitures du client :
    ***cmp test client 11/07***
    Fin des voitures du client ***cmp test client 11/07***
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(93817)--Connection(0)--acquire unit of work:5617033
    [TopLink]: UnitOfWork(5617033)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(5617033)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(5617033)--Connection(2306830)--INSERT INTO CLIENT_VOITURE (IDVOITURE, IDCLIENT
    ) VALUES (1904952, 33)
    [TopLink]: UnitOfWork(5617033)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(5617033)--Connection(0)--release unit of work
    [TopLink]: ClientSession(93817)--Connection(0)--client released
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(1283170)--Connection(0)--acquire unit of work:7803223
    [TopLink]: UnitOfWork(7803223)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(5140839)--Connection(0)--acquire unit of work:6868612
    [TopLink]: UnitOfWork(6868612)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(6868612)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(6868612)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(6868612)--Connection(0)--release unit of work
    [TopLink]: ClientSession(5140839)--Connection(0)--client released
    [TopLink]: UnitOfWork(7803223)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(7803223)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(7803223)--Connection(0)--release unit of work
    [TopLink]: ClientSession(1283170)--Connection(0)--client released
    AprÞs ajout : Voitures du client :
    ***cmp test client 11/07***cmp test voiture 11/07
    Fin des voitures du client ***cmp test client 11/07***
    Here is the one for the second without having deleted the line in the relation table :
    [TopLink]: ServerSession(529044)--Connection(7555457)--SELECT NOM, IDCLIENT FROM CLIENT WHERE (IDCLI
    ENT = 33)
    [TopLink]: ServerSession(529044)--Connection(1739386)--SELECT NOM, IDVOITURE FROM VOITURE WHERE (IDV
    OITURE = 1904952)
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(5299092)--Connection(0)--acquire unit of work:7278394
    [TopLink]: UnitOfWork(7278394)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(5339613)--SELECT t1.NOM, t1.IDVOITURE FROM CLIENT_VOITU
    RE t0, VOITURE t1 WHERE ((t0.IDCLIENT = 33) AND (t1.IDVOITURE = t0.IDVOITURE))
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(7106214)--Connection(0)--acquire unit of work:4437046
    [TopLink]: UnitOfWork(4437046)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(4437046)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(4437046)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(4437046)--Connection(0)--release unit of work
    [TopLink]: ClientSession(7106214)--Connection(0)--client released
    [TopLink]: UnitOfWork(7278394)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(7278394)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(7278394)--Connection(0)--release unit of work
    [TopLink]: ClientSession(5299092)--Connection(0)--client released
    Avant ajout : Voitures du client :
    ***cmp test client 11/07***cmp test voiture 11/07
    Fin des voitures du client ***cmp test client 11/07***
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(7385032)--Connection(0)--acquire unit of work:5105875
    [TopLink]: UnitOfWork(5105875)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(5105875)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(5105875)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(5105875)--Connection(0)--release unit of work
    [TopLink]: ClientSession(7385032)--Connection(0)--client released
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(4134178)--Connection(0)--acquire unit of work:137003
    [TopLink]: UnitOfWork(137003)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(7439747)--Connection(0)--acquire unit of work:514030
    [TopLink]: UnitOfWork(514030)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(514030)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(514030)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(514030)--Connection(0)--release unit of work
    [TopLink]: ClientSession(7439747)--Connection(0)--client released
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(7459637)--Connection(0)--acquire unit of work:2853878
    [TopLink]: UnitOfWork(2853878)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(2853878)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(2853878)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(2853878)--Connection(0)--release unit of work
    [TopLink]: ClientSession(7459637)--Connection(0)--client released
    [TopLink]: UnitOfWork(137003)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(137003)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(137003)--Connection(0)--release unit of work
    [TopLink]: ClientSession(4134178)--Connection(0)--client released
    AprÞs ajout : Voitures du client :
    ***cmp test client 11/07***cmp test voiture 11/07
    cmp test voiture 11/07
    Fin des voitures du client ***cmp test client 11/07***
    and for the third, it really doesn't make any sense :
    [TopLink]: ServerSession(529044)--Connection(1303940)--SELECT NOM, IDCLIENT FROM CLIENT WHERE (IDCLI
    ENT = 33)
    [TopLink]: ServerSession(529044)--Connection(5198675)--SELECT NOM, IDVOITURE FROM VOITURE WHERE (IDV
    OITURE = 1904952)
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(6781636)--Connection(0)--acquire unit of work:7299944
    [TopLink]: UnitOfWork(7299944)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(4416857)--SELECT t1.NOM, t1.IDVOITURE FROM CLIENT_VOITU
    RE t0, VOITURE t1 WHERE ((t0.IDCLIENT = 33) AND (t1.IDVOITURE = t0.IDVOITURE))
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(5916683)--Connection(0)--acquire unit of work:1460260
    [TopLink]: UnitOfWork(1460260)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(1460260)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(1460260)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(1460260)--Connection(0)--release unit of work
    [TopLink]: ClientSession(5916683)--Connection(0)--client released
    [TopLink]: UnitOfWork(7299944)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(7299944)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(7299944)--Connection(0)--release unit of work
    [TopLink]: ClientSession(6781636)--Connection(0)--client released
    Avant ajout : Voitures du client :
    ***cmp test client 11/07***cmp test voiture 11/07
    Fin des voitures du client ***cmp test client 11/07***
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(6791004)--Connection(0)--acquire unit of work:7735671
    [TopLink]: UnitOfWork(7735671)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(7735671)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(7735671)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(7735671)--Connection(0)--release unit of work
    [TopLink]: ClientSession(6791004)--Connection(0)--client released
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(2463085)--Connection(0)--acquire unit of work:1100193
    [TopLink]: UnitOfWork(1100193)--Connection(0)--JTS#register()
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(1574247)--Connection(0)--acquire unit of work:4041918
    [TopLink]: UnitOfWork(4041918)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(4041918)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(4041918)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(4041918)--Connection(0)--release unit of work
    [TopLink]: ClientSession(1574247)--Connection(0)--client released
    [TopLink]: ServerSession(529044)--Connection(0)--client acquired
    [TopLink]: ClientSession(660080)--Connection(0)--acquire unit of work:517121
    [TopLink]: UnitOfWork(517121)--Connection(0)--JTS#register()
    [TopLink]: UnitOfWork(517121)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(517121)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(517121)--Connection(0)--release unit of work
    [TopLink]: ClientSession(660080)--Connection(0)--client released
    [TopLink]: UnitOfWork(1100193)--Connection(0)--JTS#beforeCompletion()
    [TopLink]: UnitOfWork(1100193)--Connection(0)--JTS#afterCompletion()
    [TopLink]: UnitOfWork(1100193)--Connection(0)--release unit of work
    [TopLink]: ClientSession(2463085)--Connection(0)--client released
    AprÞs ajout : Voitures du client :
    ***cmp test client 11/07***cmp test voiture 11/07
    cmp test voiture 11/07
    Fin des voitures du client ***cmp test client 11/07***

  • Making a Many to Many CMR in Netbeans

    Anyone have any clue how to do this?
    I have the classic three tables:
    create table user (
    id integer,
    name varchar(30)
    create table role (
    id integer,
    name varchar(30)
    create table userrole (
    userid integer,
    roleid integer
    I use NB 5 to create the User and Role beans from the Database. Then I go in to the ejb-jar.xml visual editor, create a CMR that's Many to Many, UserBean to RoleBean, create a CMR field in UserBean names roles. I leave "create CMR field" for RoleBean unchecked.
    Then I go to sun-cmp-mappings.xml and open up its editor.
    Click on UserBean, see the CMP fields all mapped. On the roles field, I click the Mapped Column drop down box and select "map relationship field". This pops up a new wizard, but I can't get Next to light up, and there's nothing in the Related Bean column of fields, and they're disabled so I can not change them.
    So, I'm kind of stuck at this point and curious if someone can step me through creating this relationship.

    With Netbeans 5.5 that's very easy, if you do not encounter bugs (it is a preview release):
    Just anotate your beans :
    class User {
    @ManyToMany(mappedBy="members")
    public Collection<Role> getRoles(){
    class User {
    @ManyToMany
    public Collection<User> getMembers(){
    Then the application server will create the tables for you

  • EJBGen bug

    I'm having the following problem with WebLogic 9.1 EJBGen- whenever using it in an EJB that has static imports it throws a NullPointerException. I'm not sure if someone else experienced this problem, but it seems to be a bug.

    Saurabh Gupta <[email protected]> wrote in
    news:[email protected]:
    I am trying to use ejbgen to generate the code for many-to-many cmr
    relationships.
    I have come across a bug where the ejb-jar.xml generates a non
    compliant ejb2.0 xml tag. The actual tag should be
    <relationship-role-source> however, it generates <role-source>. Can you post (or email me) your two sources?
    Thanks.
    Cedric
    http://beust.com/weblog

  • Creating data in a many-to-many-relationship

    Hello,
    we really have problems in implementing a JClient dialog based on BC4J for creating data in a many to many relationship - especially with cascade delete on both sides.
    Simplified our tables look like:
    create table A_TABLE
    A_ID VARCHAR2(5) not null,
    A_NAME VARCHAR2(30) not null,
    constraint PK_A_TABLE primary key (A_ID),
    constraint UK_A_TABLE unique (A_NAME)
    create table B_TABLE
    B_ID VARCHAR2(5) not null,
    B_NAME VARCHAR2(30) not null,
    constraint PK_B_TABLE primary key (B_ID),
    constraint UK_B_TABLE unique (B_NAME)
    create table AB_TABLE
    A_ID VARCHAR2(5) not null,
    B_ID VARCHAR2(5) not null,
    constraint PK_AB_TABLE primary key (A_ID, B_ID),
    constraint FK_AB_A foreign key (A_ID) references A_TABLE (A_ID) on delete cascade,
    constraint FK_AB_B foreign key (B_ID) references B_TABLE (B_ID) on delete cascade
    Could JDev Team please provide a BC4J/JClient sample that performs the following task:
    The dialog should use A_TABLE as master and AB_TABLE as detail. The detail displays the names associated with the IDs. Next to AB_TABLE should be a view of B_TABLE which only displays rows that are currently not in AB_TABLE. Two buttons are used for adding and removing rows in AB_TABLE. After adding or removing rows in the intersection the B_TABLE view should be updated. The whole thing should work in the middle and client tier. This means no database round trips after each add/remove, no posts for AB_TABLE and no query reexecution for B_TABLE until commit/rollback.
    This is a very common szenario: For an item group (A_TABLE) one can select and deselect items (AB_TABLE) from a list of available items (B_TABLE). Most of JDeveloper4s wizards use this. They can handle multi/single selections, selections from complex structures like trees and so on. Ok, the wizards are not based on BC4J - or? How can we do it with BC4J?
    Our main problems are:
    1. Updating the view of B_TABLE after add/remove reflecting the current selection
    2. A good strategy for displaying the names instead of the IDs (subqueries or joining the three tables)
    3. A JBO-27101 DeadEntityAccessException when removing an existing row from AB_TABLE and adding it again
    Other problems:
    4. We get a JBO-25030 InvalidOwnerException when creating a row in AB_TABLE. This is caused by the composition. We workaround this using createAndInitRow(AttributeList) on the view object (instead of create()). This is our add-Action:
    ViewObject abVO = panelBinding.getApplicationModule().findViewObject("ABView");
    ViewObject bVO = panelBinding.getApplicationModule().findViewObject("BView");
    Row bRow = bVO.getCurrentRow();
    NameValuePairs attribList = new NameValuePairs(
    new String[]{"BId"}, new Object[]{bRow.getAttribute("BId")});
    Row newRow = abVO.createAndInitRow(attribList);
    abVO.insertRow(newRow);
    5. After inserting the new row the NavigationBar has enabled commit/rollback buttons and AB_TABLE displays the row. But performing a commit does nothing. With the following statement after insertRow(newRow) the new row is created in the database:
    newRow.setAttribute("BId", bRow.getAttribute("BId"));
    Please give us some help on this subject.
    Best regards
    Michael Thal

    <Another attempt to post a reply. >
    Could JDev Team please provide a BC4J/JClient sample
    that performs the following task:
    The dialog should use A_TABLE as master and AB_TABLE
    as detail. The detail displays the names associated
    with the IDs. Next to AB_TABLE should be a view of
    B_TABLE which only displays rows that are currently
    not in AB_TABLE. Two buttons are used for adding and
    removing rows in AB_TABLE. After adding or removing
    rows in the intersection the B_TABLE view should be
    updated. The whole thing should work in the middle
    and client tier. This means no database round trips
    after each add/remove, no posts for AB_TABLE and no
    query reexecution for B_TABLE until commit/rollback.
    This is a very common szenario: For an item group
    (A_TABLE) one can select and deselect items
    (AB_TABLE) from a list of available items (B_TABLE).
    Most of JDeveloper4s wizards use this. They can
    handle multi/single selections, selections from
    complex structures like trees and so on. Ok, the
    wizards are not based on BC4J - or? How can we do it
    with BC4J?
    Our main problems are:
    1. Updating the view of B_TABLE after add/remove
    reflecting the current selectionYou should be able to use insertRow() to insert the row into proper collection.
    However to remove a row only from the collection, you need to add a method on the VO subclasses (and perhaps export this method so that the client side should see it) to unlink a row from a collection (but not remove the associated entities from the cache).
    This new method should use ViewRowSetImpl.removeRowAt() method to remove the row entry at the given index from it's collection. Note that this is an absolute index and not a range index in the collection.
    2. A good strategy for displaying the names instead
    of the IDs (subqueries or joining the three tables)You should join the three tables by using reference (and perhaps readonly) entities.
    3. A JBO-27101 DeadEntityAccessException when
    removing an existing row from AB_TABLE and adding it
    againThis is happening due to remove() method on the Row which is marking the row as removed. Attempts to add this row into another collection will throw a DeadEntityAccessException.
    You may 'remove the row from it's collection, then call 'Row.refresh' on it to revert the entity back to undeleted state.
    >
    Other problems:
    4. We get a JBO-25030 InvalidOwnerException when
    creating a row in AB_TABLE. This is caused by the
    composition. We workaround this using
    createAndInitRow(AttributeList) on the view object
    (instead of create()). This is our add-Action:
    ViewObject abVO =
    O =
    panelBinding.getApplicationModule().findViewObject("AB
    iew");
    ViewObject bVO =
    O =
    panelBinding.getApplicationModule().findViewObject("BV
    ew");
    Row bRow = bVO.getCurrentRow();
    NameValuePairs attribList = new NameValuePairs(
    new String[]{"BId"}, new
    String[]{"BId"}, new
    Object[]{bRow.getAttribute("BId")});
    Row newRow = abVO.createAndInitRow(attribList);
    abVO.insertRow(newRow);This is a handy approach. Note that Bc4j framework does not support dual composition where the same detail can be owned by two or more masters. In those cases, you also need to implement post ordering to post the masters before the detail (and reverse ordering for deletes).
    >
    5. After inserting the new row the NavigationBar has
    enabled commit/rollback buttons and AB_TABLE displays
    the row. But performing a commit does nothing. With
    the following statement after insertRow(newRow) the
    new row is created in the database:
    newRow.setAttribute("BId",
    d", bRow.getAttribute("BId"));This bug in JDev 903 was fixed and a patch set (9.0.3.1) is (I believe) available now via MetaLink.
    >
    >
    Please give us some help on this subject.
    Best regards
    Michael Thal

  • CMR Many-to-Many Question

    Hi,
    I am doing an applicatiion using CMP. I have 2 tables in my database that have a many-to-many unidirectional relationship. Consequently, I have created a link table that takes the primary key value from both tables. It is the standard way for doing it in a relational databse. I have setup CMR fields in my appropriate bean class. My question is, will that link table be updated by the container when I create a new relationship?
    I have looked at the folowing code from the IBM website. I think it is a good example.
    The addRole() adds a role to a UserBean as follows:
    public void addRole(String email, String roleName){
        LocalUser user = userHome.findByPrimaryKey(email);
        LocalRole role = roleHome.findByPrimaryKey(roleName);
        Collection roles = user.getRoles();
        roles.add(role); The author the says "Thus, when a role gets added to the roles collection, the EJB container updates the datastore. Thus, the code that inserts the relationship in the datastore is the interface of the Collection class."
    Does he mean that a link table will be updated?
    If anyone has tried this could they please let me know.
    Thanks,
    Chris.

    Yeh I know I don't have to write to the database, but when I create my CMP bean I didnt map it to my link table. Therefore I'm not sure if the container will update the link table in my database.

  • Many "many-to-many-" questions ;)

    Hello everyone,
    1 - I am trying to use two many-to-many transactions on the same page. Everything seems to be working except that the supplemental fields are not inserting or updating into the database. No error is being returned.
    2 - Is there a way to validate the data that is being entered via these supplemental fields? I want to check that any item that is checked actually has a cost entered for it.
    Thanks for any help you can provide.
    A Read

    OK.. so I have figured out the problem with the first part of my question.<br /><br />It seems that there is a bug in the ADDT many-to-many wizzard when there are more than one of them in a form.<br /><br />The first transaction is referred to in all of the code as mtm_<whatever the fields are>, subsequent fields are referred to as mtm1_<whatever the fields are>, mtm2_<whatever the fields are>, etc.<br /><br />It seems that the wizzard does a good job of re-numbering all of these EXCEPT when it comes to the form's boxes name and id for any supplemental fields.  I had to re-number them from mtm_<blah blah> to mtm1_<blah blah> and now they work...<br /><br />Now onto the second part of my question.<br /><br />A Read

  • EJB and many-to-many relationship

    I write two CMP Beans userBean and roleBean with many-to-many relationship
    userBean:
      cmp fields: id,name
      cmr fields: userRoles
    roleBean:
       cmp fields: id,rolename
       cmr fields: usersinroleIn database I have 3 tables:
    USER( ID NUMBER PK,NAME CHAR);
      ROLE( ID NUMBER PK,ROLENAME char);
      USER_ROLE( (USERID FK(USER.ID), ROLEID FK(ROLE.ID)) PK);in sun-cmp-mappings.xml I add cmp fields mapping,
    in userBean and roleBean I add secondary table USER_ROLE
    then I add CMR mappings to userBEan nd roleBean
    ufter deploying of EJB.jar
    in client i wrote:
    userBeanLocalHome lh=lookupUser();
    lh.create(new java.math.BigDecimal(5),'username');when i run client exception occurs in server log I see:
    TransactionRollbackException because Container try to insert into USER_ROLE
    values(5(userid),null(roleid)) but user have no roles
    in that situation how can I create user without any roles?
    thanx!

    FaraPooyan, I think about this but it is not good idea because it makes 1-n:1-m relationship.
    but I whant 0-n:0-m relationship
    I resolve this problem by removing secondary table from sun-cmp-entitymappings.xml
    So it works good, but now i dont understand: when i need secondary table mapping if they are not needed for many-to-many relationships

  • Many to many relationship EJB

    hi there,
    Do you know where to find an example of a project made with the developer studio using a many to many relation ship between EJB ?
    thanks,
    FM

    Frantz,
    unfortunately I don´t have a ready-to-use sample project. But this task is well documented at sap help. You need a helper table in your data dictionary to manage the relation.
    Check this link...
    SAP Help CMP
    Try to develop your own project and ask here if you have any issues.
    Regards
    Sebastian
    Message was edited by: Sebastian Voss

  • Many-to-many relationship question

    Hello,
    Could you please provide an EXAMPLE of sun-cmp-mappings.xml with many-to-many relations (using a secondary table).
    Thanks.

    I think it is important to make the distinction between the mapping of many-to-many relations (join tables) and secondary tables.
    There is a many to many mapping in the samples. The roster sample has it. You can read through the sun-cmp-mappings.xml file for that to see how to do a join table. The fields that you want to look at are Player's teams field and Team's players field.
    The secondary table allows you to map columns from multiple tables into a single entity bean. For example:
    I may have an Address bean with the usual fields; street, city, state, and postal/zip code.
    I may need to map this Bean onto a database with the following tables
    ADDR
    STRT_KEY,
    ZIP_KEY
    and
    STRT
    STRT_KEY,
    STRT_STRING
    ZIP
    ZIP_KEY,
    CITY_STRING,
    STATE_STRING
    In my mapping for the Address bean's zip field, the mapping would need to look like:
    <entity-mapping>
    <ejb-name>Address</ejb-name>
    <table-name>ADDR</table-name>
    <cmp-field-mapping>
    <field-name>city</field-name>
    <column-name>ZIP.CITY_STRING</column-name>
    </cmp-field-mapping>
    <secondary-table>
    <table-name>ZIP</table-name>
    <column-pair>
    <column-name>ADDR.ZIP_KEY</column-name>
    <column-name>ZIP.ZIP_KEY</column-name>
    <column-pair>
    </secondary-table>
    The secondary table element defines join between the two tables, so the field can resolve to a single value.

  • Hibernate - Spring - problem with mapping (many-to-many)

    Hello,
    I want to map the following situation. I have a table called EDUCATION and a table called SCHOOLS. Between those tables I have an associative table called EDUCATION_SCHOOLS. The (usefull) fields:
    EDUCATION:
    id (long) - PK
    name (varchar)
    versionNr (long)
    SCHOOLS:
    id (long) - PK
    name (varchar)
    versionNr (long)
    EDUCATION_SCHOOLS:
    id (long) - PK
    education_id (long) (FK to EDUCATION.id)
    school_id (long) (FK to SCHOOLS.id)
    name (varchar)
    versionNr (long)
    Their is a Unique Constraint between EDUCATION_SCHOOLS.education_id and EDUCATION_SCHOOLS.school_id.
    What I want to be able to do:
    EDUCATION: select, update, insert
    SCHOOLS: select, update, insert
    EDUCATION_SCHOOLS: select, update (only the non-FK fields), insert
    I never want to delete anything in those tables. (and it's never ever going to be an option either)
    Hibernate version:
    Hibernate-Version: 3.0.5
    Mapping documents:
    Education:
    <hibernate-mapping>
         <class name="##.Education" table="EDUCATION">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">EDUCATION_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAME" type="string" />
            <set name="SCHOOLS" table="EDUCATION_SCHOOLS">
                <key column="EDUCATION_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="false" />
            </set>
    </hibernate-mapping>
    Schools:
    <hibernate-mapping>
         <class name="##.Schools" table="SCHOOLS">
              <id name="id" column="ID" type="java.lang.Long">
                   <generator class="sequence">
                        <param name="sequence">SCHOOLS_SEQ</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long"/>
              <property name="name" column="NAAM_NAME" type="string" />
            <set name="educations" table="EDUCATION_SCHOOLS" inverse="true" cascade="none">
                <key column="SCHOOL_ID" />
                <many-to-many class="##.Schools" column="SCHOOL_ID" lazy="proxy"/>
            </set>
    </hibernate-mapping>
    Education_schools:
    <hibernate-mapping>
    <class name="##.EducationSchools" table="EDUCATION_SCHOOLS">
               <id name="id" column="ID" type="java.lang.Long" unsaved-value="0">
                   <generator class="sequence">
                        <param name="sequence">SEQ_EDUCATION_SCHOOLS</param>
                   </generator>
              </id>
              <version name="versionNr" column="VERSIONNR" type="long" />
              <many-to-one name="education" class="##.Education" cascade="none" lazy="proxy"
                           column="EDUCATION_ID" not-null="true"/>
            <many-to-one name="schools" class="##.Schools" cascade="none" lazy="proxy"
                        column="SCHOOL_ID" not-null="true"/>  
    </hibernate-mapping>   
    Name and version of the database you are using:
    Oracle XE 10g
    I am able to:
    EDUCATION: select, insert, update
    SCHOOLS: select, insert, update
    EDUCATION_SCHOOLS: select
    Problems:
    EDUCATION_SCHOOLS: when I try to insert, I sometimes get unique constraint violations. (when I should get them, thus I'm trying to insert something that already exists .. but how do I stop Hibernate from Inserting?)
    EDUCATION_SCHOOLS: when I try to update, sometimes it works, but often I get:
    23:03:55,484 [http-8081-1] ERROR be.vlaanderen.lne.vea.epb.ui.struts.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    ex.getMessage() Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [##.EducationSchools] with identifier [null]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [##.EducationSchools#<null>]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):As you can see from the stacktrace I use Spring for the transactionManager: org.springframework.orm.hibernate3.HibernateTransactionManager in which I use e sessionFactory: org.springframework.orm.hibernate3.LocalSessionFactoryBean
    In my DAO, I try to save with the regular this.getHibernateTemplate().saveOrUpdate that has always worked for me.
    Another problem I have:
    when i update "name" in EDUCATION, the records with that ID are delete from EDUCATION_SCHOOLS ...
    As I am experiencing 3 different problems, I'm pretty sure something is wrong in the mapping files .. however I fail to find out what .. Any input would be greatly appreciated.
    (I translated some class/table-names, that's what the ## cause)
    Edited by: Bart_Blommaerts on Jul 29, 2008 11:53 PM

    Thank you for your input.
    When I try what you suggest, I still get the same error:
    16:39:30,406 [http-8081-1] ERROR ###.EpbExceptionHandler - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    ex.getMessage() Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [###.EducationSchools] with identifier [2]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [###.EducationSchools#2]If you had to map the database tables, I'm trying to map, how would you do it?

  • Many-to-many performance issue

    I realize that many-to-many joins have been discussed before (yes, I looked through many threads), but I'm having a slight variation on the issue. Our data warehouse has been functioning for a couple of years now, but we're now experiencing a dramatic degradation in report performance. I'll tell you everything I know and what I've tried. My hope is that someone will have an idea that hasn't occurred to me yet.
    The troubling data links deal with accounts and account_types. Each transaction will have one account, but each account can have multiple account_types and each account_type is made up of multiple accounts. It ends up looking like this:
    Transaction_cube --< account_dimension >--< account_type_table
    Given the many-to-many relationship between account and account_type, this is the only architecture I could come up with that will maintain data integrity in the transaction cube.
    I know that this is the cause of the performance issues because the reports run normally when this is removed. The volume of data obviously increases over time, but the problem appeared very suddenly -- not a gradual degradation that one would expect from a volume issue. The cube is partitioned by year and we're a little below last year's growth.
    The other fact to throw in is that the account_type table did increase in size by an additional 30% when we first noticed the problem. However, the business was able to go back and remove half of the account_types (unused types) so now the table has fewer rows than it had before we noticed the problem (~15k rows in the account_type table).
    We have tried pinning the table so that it remain in memory, but that did not help. I tried creating a materialized view combining accounts and account_types with a similar lack of improvement. I've tried adding indexes, but there is still a full-table scan. All database objects are analyzed nightly after the data load is completed.
    I'm fresh out of ideas at this point. Any suggestions and/or ideas would be greatly appreciated.

    I've thought about that. What it would mean would be aprox. 20 additional columns for each of the different account_types. Unfortunately, that would also mean that all the reports that use the account_type would have to have a condition:
    WHERE acct_type1='Income Stmt." OR acct_type2='Income Stmt." OR ....
    Since the account_types are not set up in a hierarchy and there must be only one row for account, I'm not sure that this is a feasible solution.
    Thank you for the suggestion.

  • Master - detail block (many-to-many)

    Hello, , I have 2 tables:
    1-(parts)its primary key : p_id
    2-(suppliers)its primary key : s_id
    and they have many-to-many relationship between them .
    the table Resulted from the relationship is(part_supp)
    How can I create master-detail block Based on this relationship.In other words, which of tables will be the master and which of them well be detail.
    I am using form 6i ..
    please help.....

    M3ATH wrote:
    Hello, , I have 2 tables:
    1-(parts)its primary key : p_id
    2-(suppliers)its primary key : s_id
    and they have many-to-many relationship between them .Many to many relation between two table isn't a good database design. You have to a junction table between them.
    the table Resulted from the relationship is(part_supp)Is this your junction table(part_supp) ?
    >
    How can I create master-detail block Based on this relationship.In other words, which of tables will be the master and which of them well be detail.If part_supp is your junction table between parts and suppliers then, try this..
    Use the junction table as a hidden block, then establish a standard Forms relation between
    Parts and (hidden)part_supp then between part_supp and suppliersHope this helps

Maybe you are looking for

  • How can I use a pic from iPhoto as a background for a page, How can I use a pic as a background for a page

    How can I use a pic from iPhoto as a background for a page, How can I use a pic as a background for a page

  • Insufficient bandwidth

    I'm trying to set up an iChat video chat with my dad. We both have an brandnew iMac with iSight build in. Both have an ADSL with more then 250kps upload (should be enough for ichat videoconferencing, isn't it?) And still we get the warning insufficie

  • Mail Preview default font too small

    Recently upgraded to Maverick and the preview font size for Apple Mail is too small.  Can change this for individual mail using apple-+, however this doesn't set the default.  Is there a preference to change the font or terminal command?

  • HP support Assistant windows 8.1

    I'm running the latest version of HP support assistant but the Tune Up won't complete (17 hours).   When I search for HP Support Assistant in Programs I get no match so I can't uninstall it (Don't understand this).  Other pages within the Support ass

  • Function module does not update the storage location in delivery

    Hello, I've been trying to use SD_DELIVERY_UPDATE_PICKING to update the storage location in SD return deliveries, without any success. Any clues? The FM works fine when it comes to updating the picking quantity, but the storage location issue still p