Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Composite key mapping.

Avatar

Former Community Member

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 Accepted Solution

Avatar

Correct answer by
Former Community Member

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

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

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

Avatar

Employee
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

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----