2 Replies Latest reply on May 6, 2010 1:11 PM by JZ

    Composite key mapping.

    Amit Gadkari Level 1

      I have table, which have composite key as primary key. (I am creating entity from editor. Database contain many tables, hence list of tables are not displayed in data model editor)

      While creating entity I have mapped both field (which are primary keys in database ) as Id fields (OrderNumber and itemNumber)

      After deploying model on server and executing code, I am not getting result.

      Also no error message is displayed on console of LCDS server.

      Can composite key be used in data modeling. If yes, what is proper way to configure composite key.

       

      I am using LCDS 3.1 and lastest version of plugin for Flash Builder 4

       

      <entity name="LineItemBean" persistent="true">

                  <annotation name="VisualModeler" width="239" height="123" x="293" y="51"/>

                  <annotation name="ServerProperties" ServerType="LCDS"/>

                  <annotation name="DMS" Table="ADVJPMT.ITEMS" use-transactions="false"/>

                  <annotation name="ActionScriptGeneration" Package="valueObjects" ImplicitServicePackage="services"/>

                  <id name="orderNumber" type="integer" generated="false">

                        <annotation name="DMS" ColumnName="ORDER_NUMBER"/>

                  </id>

                  <id name="itemNumber" type="integer" generated="false">

                        <annotation name="DMS" ColumnName="ITEM_NUMBER"/>

                        <annotation name="ActionScriptGeneration" DisableAutoReCalc="true"/>

                  </id>

                  <property name="quantity" type="integer">

                        <annotation name="DMS" ColumnName="QUANTITY"/>

                        <annotation name="ActionScriptGeneration" DisableAutoReCalc="true"/>

                  </property>

            </entity>

       

        • 1. Re: Composite key mapping.
          svetlinK

          Hi Amit,

           

          This use case should certainly work and I don't see anything wrong in your model as it is. Can you give some more information on what exactly you are trying to execute? Are you running LineItemBeanService.getAll()? That is the simplest fill/filter you can try to see if the model was configured correctly.

           

          To see what may be going wrong, you can try a few things:

          1. Enable debug logging. Open services-config.xml in the WEB-INF/flex directory of your LCDS webapp. Near the bottom of the file, find logging->target and change the level attribute to "Debug".

          2. Try getting data from the ITEMS table with a direct SQL query ("Select * from ITEMS") in the RDS Query Viewer (Data Model perspective, RDS Dataview)

           

          See if running the query directly to the database gives you the expected result and if yes, see the server logs to check what is going on when the server receives the getAll request.

           

           

          _______________

           

          That said, the LineItemBean entity in your model makes me think that you might also have an OrderBean entity and an ItemBean entity in your model. I am guessing an Order consists of a few LineItems, each with some quantity, and a given Item may appear in many Orders. If that is the case, you may want to consider modeling this data with associations between the LineItemBean entity and the OrderBean and the ItemBean entities. That would mean that the ORDER_NUMBER and ITEM_NUMBER columns in your table will be both primary keys and foreign keys and your model will look like this:

           

          <entity name="OrderBean" ... />

          <entity name="ItemBean" ... />

           

          <entity name="LineItemBean" ... >

              <id name="orderBean" type="OrderBean">

                  <annotation name="DMS" JoinColumns="ORDER_NUMBER"/>

              </id>

              <id name="itemBean" type="ItemBean">

                  <annotation name="DMS" JoinColumns="ITEM_NUMBER"/>

              </id>

              <property name="quantity" type="integer"/>

          </entity>

           

          Give this a try, if it sounds reasonable (I was just guessing about your use case here)

           

          Thanks,

          Svetlin

          • 2. Re: Composite key mapping.
            JZ Adobe Employee

            Hi Amit,

             

            Yes, the composite key as the primary key use case is definitely supported.   I have tried your model with HSQL database.  The only thing I need to change is to use a simple table name, such as "items".  Otherwise it didn't see any problem.  You can turn on debugging using Model.* filter in service-config.xml and see if you get any partilar error.

             

            HTH.

            JZ