Ejb relationships using cmp field

I have defined a cmp relationship using cmr field. Als defined getter/setter for that field.
When I call the getter method container returns all the records for relation.
getter/setter is implemented by container.
My question is can we define in which order relationships record should be retrieved. I mean can we specify Order By caluse for that.

if you want to do this you just have to use Map on collection side of your relationship like this:
@OneToMany(cascade={CascadeType.ALL})
    @JoinColumn(name="CUSTOMER_ID")
@MapKey(name="number")
@OrderBy
("number ASC")
    public Map<String, Phone> getPhoneNumbers

Similar Messages

  • 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.

  • A cmr-field and a cmp-field on the bean are using the same name. The names

    Hi:
    I am using weblogic 8.1 and MyEclipse 5.1.1. I am deploying my ear application through MyEclipse 5.1.1 as an ear file.
    When I ran the following EJB QL:
    SELECT OBJECT(p) FROM Product p.category = ?1
    I get the following error:
    n relation Category-Product, a cmr-field and a cmp-field on the bean are using the same name. The names of cmr and cmp fields must be unique.
    It is basically complaining that I have a field
    <cmr-field>
                             <cmr-field-name>category</cmr-field-name>
                        </cmr-field>
    in my ejb-jar.xml and also the same category in the
    <cmp-field><field-name>category</field-name></cmp-field>
    field. The problem is that if I changed the value of the cmr-field, I have to add a get and set in my productLocal.java and when you do that you have to do the same in the ejb-jar.xml.
    Here is my ejb-jar.xml:
    <?xml version="1.0"?>
    <!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>
    <enterprise-beans>
    <entity>
    <ejb-name>CategoryEJB</ejb-name>
    <local-home>com.CategoryHomeLocal</local-home>
    <local>com.CategoryLocal</local>
    <ejb-class>com.CategoryBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Integer</prim-key-class>
    <reentrant>False</reentrant>
    <cmp-version>2.x</cmp-version>
    <abstract-schema-name>Category</abstract-schema-name>
         <cmp-field><field-name>categoryId</field-name></cmp-field>
    <cmp-field><field-name>categoryName</field-name></cmp-field>
    <cmp-field><field-name>picture</field-name></cmp-field>
    <cmp-field><field-name>pictureWidth</field-name></cmp-field>
    <cmp-field><field-name>pictureHeight</field-name></cmp-field>
    <cmp-field><field-name>labelOn</field-name></cmp-field>
         <cmp-field><field-name>labelOff</field-name></cmp-field>
         <cmp-field><field-name>button</field-name></cmp-field>
    <primkey-field>categoryId</primkey-field>
    <security-identity><use-caller-identity/></security-identity>
              <query>
                   <query-method>
                        <method-name>findCategory</method-name>
                        <method-params></method-params>
                   </query-method>
                   <ejb-ql>
                        SELECT OBJECT(c) FROM Category c
                   </ejb-ql>
              </query>
         </entity>
         <entity>
    <ejb-name>ProductEJB</ejb-name>
    <local-home>com.ProductHomeLocal</local-home>
    <local>com.ProductLocal</local>
    <ejb-class>com.ProductBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Integer</prim-key-class>
    <reentrant>False</reentrant>
    <cmp-version>2.x</cmp-version>
    <abstract-schema-name>Product</abstract-schema-name>
         <cmp-field><field-name>productId</field-name></cmp-field>
    <cmp-field><field-name>brandName</field-name></cmp-field>
    <cmp-field><field-name>productDescription</field-name></cmp-field>
    <cmp-field><field-name>purchasePrice</field-name></cmp-field>
    <cmp-field><field-name>category</field-name></cmp-field>
    <primkey-field>productId</primkey-field>
    <security-identity><use-caller-identity/></security-identity>
              <query>
                   <query-method>
                        <method-name>findProduct</method-name>
                        <method-params>
                        <method-param>com.CategoryLocal</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        SELECT OBJECT(p) FROM Product p.category = ?1
                   </ejb-ql>
              </query>
         </entity>
    </enterprise-beans>
    <relationships>
                   <ejb-relation>
                   <ejb-relation-name>Category-Product</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>
                             Category-has-many-Product-numbers
                        </ejb-relationship-role-name>
                        <multiplicity>one</multiplicity>
                        <relationship-role-source>
                             <ejb-name>CategoryEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>productNumbers</cmr-field-name>
                             <cmr-field-type>java.util.Collection</cmr-field-type>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>
                             Product-belongs-to-Category
                        </ejb-relationship-role-name>
                        <multiplicity>many</multiplicity>
                        <cascade-delete/>
                        <relationship-role-source>
                             <ejb-name>ProductEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>category</cmr-field-name>
                        </cmr-field>
                   </ejb-relationship-role>
              </ejb-relation>
    </relationships>
    <assembly-descriptor>
    <security-role>
    <role-name>Employees</role-name>
    </security-role>
    <method-permission>
    <role-name>Employees</role-name>
    <method>
    <ejb-name>CategoryEJB</ejb-name>
    <method-name>*</method-name>
    </method>
    </method-permission>
    <container-transaction>
    <method>
    <ejb-name>CategoryEJB</ejb-name>
    <method-name>*</method-name>
    </method>
    <method>
    <ejb-name>ProductEJB</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>     
    Here is my weblogic-cmp-rdbms-jar.xml:
    <!DOCTYPE weblogic-rdbms-jar PUBLIC
    '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN'
    'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>
    <weblogic-rdbms-jar>
    <weblogic-rdbms-bean>
         <ejb-name>CategoryEJB</ejb-name>
    <data-source-name>ShoeStore</data-source-name>
         <table-map>
              <table-name>category</table-name>
              <field-map>
              <cmp-field>categoryId</cmp-field>
              <dbms-column>categoryID</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>categoryName</cmp-field>
              <dbms-column>categoryName</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>picture</cmp-field>
              <dbms-column>Picture</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>pictureWidth</cmp-field>
              <dbms-column>PictureWidth</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>pictureHeight</cmp-field>
              <dbms-column>PictureHeight</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>labelOn</cmp-field>
              <dbms-column>LabelOn</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>labelOff</cmp-field>
              <dbms-column>LabelOff</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>button</cmp-field>
              <dbms-column>Button</dbms-column>
              </field-map>
    </table-map>
    <automatic-key-generation>
    <generator-type>SQL_SERVER</generator-type>
    </automatic-key-generation>
    </weblogic-rdbms-bean>
    <weblogic-rdbms-bean>
         <ejb-name>ProductEJB</ejb-name>
    <data-source-name>ShoeStore</data-source-name>
         <table-map>
              <table-name>PRODUCT</table-name>
              <field-map>
              <cmp-field>productId</cmp-field>
              <dbms-column>productId</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>brandName</cmp-field>
              <dbms-column>brandName</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>productDescription</cmp-field>
              <dbms-column>productDescription</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>purchasePrice</cmp-field>
              <dbms-column>purchasePrice</dbms-column>
              </field-map>
              <field-map>
              <cmp-field>category</cmp-field>
              <dbms-column>categoryId</dbms-column>
              </field-map>
    </table-map>
         <!-- Automatically generate the value of ID in the database on inserts using sequence table -->
    <automatic-key-generation>
    <generator-type>SQL_SERVER</generator-type>
    </automatic-key-generation>
    </weblogic-rdbms-bean>
    <weblogic-rdbms-relation>
         <relation-name>Category-Product</relation-name>
    <weblogic-relationship-role>
    <relationship-role-name>Product-belongs-to-Category</relationship-role-name>
              <relationship-role-map>
    <column-map>
    <foreign-key-column>categoryId</foreign-key-column>
    <key-column>categoryID</key-column>
    </column-map>
              </relationship-role-map>
    </weblogic-relationship-role>
    </weblogic-rdbms-relation>
    </weblogic-rdbms-jar>
    Here is my productLocal.java:
    package com;
    import javax.ejb.CreateException;
    import javax.naming.NamingException;
    import java.util.Date;
    import java.util.Vector;
    import java.util.Collection;
    public interface ProductLocal extends javax.ejb.EJBLocalObject
         public Integer getProductId();
         public void setProductId(Integer productId);
         public String getBrandName();
         public void setBrandName(String brandName);
         public String getProductDescription();
         public void setProductDescription(String productDescription);
         public Double getPurchasePrice();
         public void setPurchasePrice(Double purchasePrice);
    public CategoryLocal getCategory();
         public void setCategory(CategoryLocal category);
    Here is my ProductBean.java:
    package com;
    import javax.naming.InitialContext;
    import javax.ejb.EntityContext;
    import javax.ejb.CreateException;
    import javax.naming.NamingException;
    import java.util.Date;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Vector;
    import java.lang.Integer;
    public abstract class ProductBean implements javax.ejb.EntityBean
         public Integer ejbCreate(Integer id)
              this.setProductId(id);
              return null;
         public void ejbPostCreate(Integer id)
         //public abstract Integer getCategoryId();
    //     public abstract void setCategoryId(Integer categoryId);
         public abstract CategoryLocal getCategory();
         public abstract void setCategory(CategoryLocal category);
         public abstract Integer getProductId();
         public abstract void setProductId(Integer productId);
         public abstract String getBrandName();
         public abstract void setBrandName(String brandName);
         public abstract String getProductDescription();
         public abstract void setProductDescription(String productDescription);
         public abstract Double getPurchasePrice();
         public abstract void setPurchasePrice(Double purchasePrice);
         public void setEntityContext(EntityContext ec)
              System.out.println("ProductBean setEntityContext");
         public void unsetEntityContext()
              System.out.println("ProductBean unsetEntityContext");
         public void ejbLoad()
              System.out.println("ProductBean ejbLoad");
         public void ejbStore()
              System.out.println("ProductBean ejbStore");
         public void ejbActivate()
              System.out.println("ProductBean ejbActivate");
         public void ejbPassivate()
              System.out.println("ProductBean ejbPassivate");
         public void ejbRemove()
              System.out.println("ProductBean ejbRemove");
    What do I needed to do to fix this problem.
    Any hint or help would be greatly appreciated!!!
    Yours,
    Frustrated

    cmr field which is "category" in ur mapping , u can't use as cmp field in abstract schema mapping. just remove category from cmp field . and every thing is fine

  • Same CMR and CMP field in relationship bean

    Hi,
         I'm trying to deploy a 1:N realtion, it all works well
    but the many part of relation when ever i try to update i get an
    error stating. A CMP cum CMR field should not have a setter method
    and it should be read only. Is there i'm doign anything wrong?
    operation:
    Bean A-- Bean B 1-N
    update foreign key of Bean B , throws exception stating there should not
    be setter.
    How to handle a CMP field as CMR.??
    Help appreciated,
    Thanks,
    Venki

    Table A
    prim key
    table B
    prim key
    Foreign Key
    A--- B is 1-- N
    when i try to create Table B using
    setForeignKey()method i get the following error.
    Error :
    javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapp
    ed to the same column, the setXXX method for the cmp-field may not be called.
    T he cmp-field is read-only.
    "Venki" <[email protected]> wrote:
    >
    Deepak
    What if i use the same field for CMP and CMR?
    projectId CMP as well as CMR.
    I cannot have two methods right?
    Venki
    Deepak Vohra <[email protected]> wrote:
    In the bean class should be a get<Cmp-Field>() method and get<Cmr-Fields>()
    method.
    public abstract <Cmp-Field-Type> get<Cmp-Field>(){}
    public abstract java.util.Collection get<Cmr-Fields>(){}
    Venki Seshaadri wrote:
    Hi,
    I'm trying to deploy a 1:N realtion, it all works well
    but the many part of relation when ever i try to update i get an
    error stating. A CMP cum CMR field should not have a setter method
    and it should be read only. Is there i'm doign anything wrong?
    operation:
    Bean A-- Bean B 1-N
    update foreign key of Bean B , throws exception stating there shouldnot
    be setter.
    How to handle a CMP field as CMR.??
    Help appreciated,
    Thanks,
    Venki

  • Comp. Primary key class-field mapping to DB columns problem.(EJB 2.0 CMP)

    Hi!
    I have deal with EJB 2.0 CMP bean.
    I have a composite PK so use the java class to store it. And there is a corresponding field in the Entity Bean with its primary key class type.
    The problem is: when deployment tool creates sql query for the findByPrimaryKey(PKClass ck)
    where ck is an object with 3 fielde : a_id, b_id, c_id.
    it says:
    <sql>SELECT "ck" FROM "MyTable" WHERE "ck" = ? </sql>
    And it means by the "ck" simple a column in DB but NOT the composite key which has to be splited into 3 different fields. So the container can't do the proper mapping.
    Does anyone know solutions?

    I was wrong about primary key class fields, take a look at Ejb2.0 Specification (10.8.2):
    The primary key class must be public, and must have a public constructor with no parameters.
    All fields in the primary key class must be declared as public.
    The names of the fields in the primary key class must be a subset of the names of the container-managed
    fields. (This allows the container to extract the primary key fields from an instance�s container-managed
    fields, and vice versa.)
    Right now I'm using BMP and I don't have this problems. Primary keys, calculated fields and types not supported by the DB can be easily achieved. But I understand your interest on CMP, is clearly evolving!

  • Using rownum in EJB-QL ..Pagination using CMP 2.1

    Hi ,
    Hope this is the right forum .. rather than JDBC .
    My requirement is to implement Pagination using EJB2.1 on weblogic with Oracle DB. This is for an application which is quite old system and is not ready yet to be migrated to EJB3.0. So we are struck with EJB2.1 at the moment.
    We are using EJB-QL to get Search result and now need to add Pagination logic in it. I can find weblogic.ejb.PreparedQuery.setMaxElements() API to specify the upper limit but what am looking for is a lower limit ..somthing like setFirstRow() ..
    Can it be done using CMP Entity Bean 2.1 .. EJBQL or someother way ?
    I have the sql for pagination but am not sucessful in translating it to EJB-QL
    select * from
    select /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum from
    (your_query_goes_here) a
    where ROWNUM <=:MAX_ROW_TO_FETCH
    where rnum >= :MIN_ROW_TO_FETCH;
    Thanks in advance ! I hope I get a solution soon ..
    Edited to get some answers !!!
    is it possible to use rownum in EJBQL ? I know rownum is specific to Oracle and my application will stay with Oracle. I get this exception
    "EJB QL compilation encountered error: [EJB:013042]The Identifier 'rownum' is neither a cmp-field nor a cmr-field. Re-examine your query."
    Edited by: user11305835 on Oct 12, 2009 10:48 PM

    Beevin
      Both two are not even validated,
      but with the first one as select max(c.id) from customer as c , in this case it is validated but while deploying it is error as , object must be return
      But when i saw  the ejb2.1 specification we can write this type of queries also ?
      Is it problem with was any thing
    Regards
    Somaraju

  • Mapping the CMP Fields with the Database Table using Websphere???

    Hi,
    How to Map the CMP Fields with the Database Table using Websphere
    thru ejb.jar.xml???
    Thanks,
    JavaCrazyLover

    Hi,
    How to Map the CMP Fields with the Database Table using Websphere
    thru ejb.jar.xml???
    Thanks,
    JavaCrazyLover

  • Javax.ejb.EJBException: Method is not a known CMP field accessor...

    Hi !
    I have a little problem. When I deploy my jar file, I have the next message :
    "javax.ejb.EJBException: Method is not a known CMP field accessor, CMR field accessor, or ejbSelect method: methodName=compareTo"
    Is there someone to tell me why ? ^_^
    I didn't put the source code in this topic, not to pollute it, but if you need it, tell me ;)
    Thx for your help.

    Hi Spidey !
    Thx for you help but... Giving my method doesn't require the use of EJBQL, I don't think I have to define it in my deployment descriptor (this is not a query)...
    I give you an idea of my (experimental ^_^) source code :
    public class CountryBean implements EntityBean{
    public int compareTo(Country c){
    SOP("COMPARE TO");
    return 0;
    public class MySession implements SessionBean{
    public int doIt(){
    MyComparator comparator = new MyComparator();
    return comparator.compare(country1, country2);
    public class MyComparator implements Comparator{
    public int compare(Object o1, Object o2){
    return compare((Country)o1, (Country)o2);
    public int compare(Country c1, Country c2){
    SOP("COMPARE");
    return c1.compareTo(c2);
    When I call doIt(), the message "COMPARE" is written and just after, there's this message (the message "COMPARE TO" is never written):
    "11:29:44,204 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
    javax.ejb.EJBException: Method is not a known CMP field accessor, CMR field accessor, or ejbSelect method: methodName=compareTo
    at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:110)
    at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
    at CountryBean$Proxy.compareTo(<generated>)"
    I hope this is clear ^__^
    Thx for helping me ;)

  • Adding CMP-fields to a EJB in sun ONE studio 5

    I have a CMP EJB, and initialized its fields against a table in a database (PointBase). When I later try adding additional fields, these fields naturally doesnt exist in the database.
    Then i make a test-module for the CMP EJB. When I try mapping the CMP-fields, I get in trouble with the field that doesnt exist in the database-table.
    How can I get around this problem, must I really manually update the database schema, or can I somehow "tell" SUN ONE studio to make the field for me.

    yes, but is there a way of letting J2EE handle all
    this "Under the hood", so i dont even have to worry
    about the internal datastructure in the database?You could drop the table from the database and then have Studio or deploytool create the tables (now with the additional fields) on deployment.
    -Ian Evans
    Sun Microsystems
    J2EE Tutorial team

  • Orion-ejb-jar: cmp-field-mapping specs REMOTE home

    In the tech. preview documentation, in the EJB dev. guide, and in the section which details the orion-ejb-jar, I noticed something odd about the "cmp-field-mapping" element. It has an attribute called "ejb-reference-home", which is supposed to be "the JNDI location of the fields remote EJB-home if the field is an entity EJBObject or EJBHome".
    I would assume this would only be set if this field was specified as a CMR field in the ejb-jar.xml file.
    The odd thing is, it specifies the REMOTE home, not the LOCAL home. Is this just a typo?

    I believe that it is not JDeveloper issue but OC4J one. It does not pick up new orion-ejb-jar.xml if you re-deploy bean(s). It should deploy your orion-ejb-jar.xml when you're deploying yor application for the first time (so there is not orion-ejb-jar.xml in deployments directory). If you want OC4J to pick changes up remove orion-ejb-jar.xml from $OC4J_HOME/application-deployments/<application>/<Bean>.jar/ and then deploy it either manually or with JDeveloper. I hope it will help.

  • All cmp-fields that double as cmr-fields must have an object type??

    Greetings,
    I'm deploying an application in weblogic 8.1sp2 that worked fine in
    jboss 3.2. The error is:
    Exception:weblogic.management.ApplicationException: prepare failed for
    ServiceEJB.jar Module: ServiceEJB.jar Error: Exception preparing module:
    EJBModule(ServiceEJB.jar,status=NEW) Unable to deploy EJB:
    ServiceEJB.jar from ServiceEJB.jar: [EJB:011017]Error while reading
    'META-INF/weblogic-cmp-rdbms-jar.xml'. The error was: In relationship
    'primitive_TO_primitive_param', role
    'primitive_param_BELONGS_TO_primitive', a cmp-field used to implement
    this relationship has a primitive type. All cmp-fields that double as
    cmr-fields must have an object type. . at
    weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:255) at
    Does it means that I should cmp field from "int" type to "Integer"
    object??? If true, I really don't know why the requirement since in
    jboss worked just fine. But do you confirm it?
    regards,
    Pedro Salazar

    I believe there is a requirement that any field used as a primary or
    foreign key must be an object and implement hashCode/equals.
    I'd post in weblogic.developer.interest.ejb.cmp if you want more
    information.
    -- Rob
    Pedro Salazar wrote:
    Greetings,
    I'm deploying an application in weblogic 8.1sp2 that worked fine in
    jboss 3.2. The error is:
    Exception:weblogic.management.ApplicationException: prepare failed for
    ServiceEJB.jar Module: ServiceEJB.jar Error: Exception preparing module:
    EJBModule(ServiceEJB.jar,status=NEW) Unable to deploy EJB:
    ServiceEJB.jar from ServiceEJB.jar: [EJB:011017]Error while reading
    'META-INF/weblogic-cmp-rdbms-jar.xml'. The error was: In relationship
    'primitive_TO_primitive_param', role
    'primitive_param_BELONGS_TO_primitive', a cmp-field used to implement
    this relationship has a primitive type. All cmp-fields that double as
    cmr-fields must have an object type. . at
    weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:255) at
    Does it means that I should cmp field from "int" type to "Integer"
    object??? If true, I really don't know why the requirement since in
    jboss worked just fine. But do you confirm it?
    regards,
    Pedro Salazar

  • How to add new CMP field to CMP bean

    I am back for your amusement. I have seen similar things to this in other postings, but I have not been able to find one that, when action is taken, solves my problem.
    I am using Sun Java Studio Enterprise 7 2004Q4
    Our database changed by adding one new field. I need to update the bean for that table. Since the bean was created from a schema, I thought I need to update the schema first. Having found no way to do that yet, I recreated the schema under a different name, deleted the old one and renamed the new one to the old name. Follow that? :|
    Ok. So now I have a new schema with the old name. I still have the old one in CVS so I can get it back (see I am learning someting).
    I then went to the bean and added a new CMP field. I updated all my code to use the new field accessors. Changed the create method to have one more field and use the accessor.
    Then in the module where the bean is being used I mapped the new field to the field in the database. The CMP is in a relationship with two other beans, but this field is not used (not yet anyway).
    I then compiled and depoyed. Everything went ok. "I am really getting the hang of this EJB stuff", I said to my self. Then I tried to run it.... I should have saved the comment for another time... :(
    I got this message and exception :
    "Validation error in class com.PersonCMPBean685435892_JDOState: com.sun.jdo.api.persistence.model.util.ModelValidationException: Warning: Cannot find the column person.p_umd_id for mapping the field pUmdId in the class com.PersonCMPBean685435892_JDOState.
    Verify that the schema file exists and that its contents are correct."
    com.sun.jdo.api.persistence.support.JDOUserException: The mapping for class com.PersonCMPBean685435892_JDOState is invalid. Compile the class in the IDE, correct any errors, and verify that all required files are packaged for execution.
    The schema exists. The field is in the new schema. Hmmm. I screwed up. Stamp it on my forehead with the others from working with EJB.... :)
    So what did I do wrong? How is this supposed to be done. Is there an easier way to update the schema?
    Any help will be greatly appreciated. Thank you.

    Ok. I found something that works, albeit I don't think it is the recommended way. But since I can't find a recommended way, I will settle for working. This was a suggestion from someone else who had this problem ( http://swforum.sun.com/jive/thread.jspa?forumID=122&threadID=23428 ). But I have broken it down into steps and refined it a bit.
    1. Create a new schema under a different name.
    2. Go to the module that has a bean that is using the old schema.
    3. Find the reference for the bean under the module and look at the properties for the bean.
    4. In the properties in the Sun Java System As section there is a property called Mapped Schema. Change it to the new schema.
    5. deploy
    There's more...
    If you need to have the same name for the schema, like I did because I keep it in CVS, do this:
    6. Shutdown the IDE
    7. Go to the directory where the schema is and rename it to whatever you need (whatever you had originally).
    8. restart the IDE
    9. repeat steps 2-4
    10. restart the IDE again before you deploy!
    I know this is insane. But it is all I could figure out so far. If anybody has something else that is better, please, please, please let me know!

  • Collection sort of relation CMP field

    can I sort collection of relation CMP field declarativly?
    in orion-ejb-jar.xml?
    now I can do it either in SessionBean code or by creation of one more method findByFK1 - additional work -((

    I have one cmp ejb call 'R' with primary key id.
    Another cmp ejb call 'RS' with primary key id as well. This RS suppose to represent status of the R record which one R record may have multiple status.
    I added one cmp field from toplink workbench call 'status' under R and another cmp field call 'req' under RS. I did a one to many mapping on 'status' with reference descriptor RS bean. Then, I added another one to one mapping on 'req' with reference descriptor R bean.
    I got the new ejb-jar.xml after saving the project with the new relationships. However I get the error (as described in previous posting) from ejbc.
    My two attempts:
    1) If I remove that 1:1 relationship, ejbc is ok but data cannot be retrieve properly.
    2) I tried to remove the
    <cmp-field>
    <field-name>req</field-name>
    </cmp-field>
    manually from the ejb-jar.xml under 'RS' bean, ejbc is ok as well but again, data cannot be retrieved.
    I looked at the demos provided by toplink 4.0 installation, apparently they were able to add a mapping without using 'add cmp field' (this function automaticaly generates the <cmp-field> tags..)
    Thanks,
    Ivy

  • Cmp-field is read-only

    Say I have beans A and B where A <- B (unidirectional relationship)
    and A.cmp_A and B.cmr_A point to same db field
    I try this and get exception as below while doing A.setCmp_A()
    javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped
    to the same column, the setXXX method for the cmp-field may not be called. The
    cmp-field is read-only.
    the cmp-field and cmr-field are in separate beans.
    F1

    Say I have beans A and B where A <- B (unidirectional relationship)
    and A.cmp_A and B.cmr_A point to same db field
    I try this and get exception as below while doing A.setCmp_A()
    javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped
    to the same column, the setXXX method for the cmp-field may not be called. The
    cmp-field is read-only.
    the cmp-field and cmr-field are in separate beans.
    F1

  • How to use CMP with Inheritance?

    I've a thorny problem with 2 EJBs which I hope I can use CMP for persistence.
    I'm supposed to implement a web-based forum and I'm thinking of using a ForumThread entity bean and a ForumReply entity bean to store the postings/messages in the forum.
    A ForumReply, according to OO design, is the same as a ForumThread (which is the first message of a topic) except that they've a parent thread/reply. So I thought of using Inheritance with the ForumThread as the parent (base) class and ForumReply as the sub (derived) class.
    But it seems that CMP in EJB 2.0 does not support this relationship as yet. Is there any way to workaround this limitation without having to remodel the relationship? What should I do in such a situation? Anyone care to share how he overcome this?
    It's not quite possible to give up inheritance in OO design simply because EJB 2.0 CMP doesn't support it right? We end up creating bad softwar design.
    So do I have to go back to using Bean Managed Persistence in this case?

    I hate CMP. Why don't you use JDO or Hibernate?
    Anyway, if you want to do it with CMP, here is your solution: http://www.theserverside.com/resources/article.jsp?l=EJBInheritance

Maybe you are looking for

  • XAML DataContext: name does not exist in the namespace

    I have created a new C# WPF Application project in VS 2013, named dataconfigtest.  The namespace is dataconfigtest. I add a new, public class named "TestDataClass".  It is also in the dataconfigtest namespace. I add the following code to the XAML fil

  • OWSM GATEWAY VIRTUALIZED BPEL PROCESS INVOCATION PROBLEM

    Hi This is the error i am getting when i try to invoke the VIRTUALIZED BPEL process from test page of OWSM. i have created a component and added service to it. But this error surfaced when i try to invoke the service. I can see the virtualized WSDL i

  • CMP Bean - weblogic.transaction.internal.TimedOutException

    Hi, I have two CMP beans. Bean1 is stateless bean and Bean2 is stateful. I am using a method of Bean2 from Bean1 and later on call Bean1.remove(). Now, I am getting the following error in my application. I would appreciate any help. Thanks, SamK webl

  • How can one get Facetime for an Ipod Touch version 4.2

    Purchased Itouch last year.  Would like to install FaceTime app.  Can not find it on Itunes.  Is it even available?

  • HT201412 How do I stop my apps from quitting unexpectedly?

    I've had my iPod touch for about a year now and it's always worked fine. Ever since I updated it to the newest iOS, it's been running slower and doesn't respond sometimes. For example it freezes a lot, it doesn't go to the home screen after I press t