【问题标题】:ATG - One to Many mapping and list property resultsATG - 一对多映射和列表属性结果
【发布时间】:2018-01-08 21:45:04
【问题描述】:

我正在尝试做一些我应该很简单的事情......但是我遇到了一些问题。

表省:

CODISTPROV  NAME     SIGPROV
1           MILAN    MI
2           ROME     RM
3           NAPLES   NA

和 TABLE COMUNI:

CODISTPROV CODISTCOM DESC_COM
1          1         XX1
1          2         XX2
2          3         YY3
2          4         YY4
3          5         ZZ5

COMUNI 中的 CODISTPROV 是 PROVINCE 的外键。

xml是

<item-descriptor name="comuniWithSiglaProvincia" writable="false" item-cache-timeout="86400000" item-expire-timeout="604800000">
   <table name="province" type="primary" id-column-names="codistprov">
        <property name="sigla_provincia" data-type="String" column-name="sigprov" display-name-resource="Sigla provincia"/>      
   </table>
   <table name="comuni" type="multi" id-column-names="codistprov,codistcom" multi-column-name="codistcom">      
            <property name="listaComuni" data-type="list" component-data-type="String" column-name="desc_com" />            
   </table>
</item-descriptor>

我想实现这个查询

SELECT C.DESC_COM,P.SIGPROV 
FROM COMUNI C, PROVINCE P 
WHERE C.DESC_COM LIKE 'PAR%' AND C.CODISTPROV = P.CODISTPROV;

其中 PAR 是输入中的一些字符。 代码:

RepositoryView view = getTopoAnagraficaRepository().getView("comuniWithSiglaProvincia");
Object params[] = new Object[1];
params[0] = comuneInitialCharacters;

QueryBuilder repositoryBuilder = view.getQueryBuilder();
QueryExpression prop = repositoryBuilder.createPropertyQueryExpression(PROPERTY_LISTA_COMUNI);
QueryExpression value = repositoryBuilder.createConstantQueryExpression(new String(comuneInitialCharacters));                                           
Query query = repositoryBuilder.createPatternMatchQuery(prop, value, QueryBuilder.STARTS_WITH);

listRepItem = view.executeQuery(query); // 19 results
if(listRepItem != null){
for (RepositoryItem item : listRepItem) {
        System.out.println("PROV=" + item.getPropertyValue("sigla_provincia")); // it prints correct value
    if (item.getPropertyValue("listaComuni") != null)  // ArrayIndexOutOfBoundException
     [...]

查询返回 19 listRepItem(它是正确的)但是当我尝试访问子列表时,我在上面的最后一行中得到了 ArrayIndexOutOfBoundException。

有什么提示吗? 访问作为列表的属性值的正确方法是什么?

以上面的数据为例,如果输入字符是“XX”,我应该得到结果

XX1 MI
XX2 MI

谢谢

【问题讨论】:

  • 请确认您是否在“Nucleus running ...”消息之前的日志中收到与存储库相关的任何错误?
  • 是的,我确认了
  • 请在问题中包含您看到的错误?

标签: sql oracle join repository atg


【解决方案1】:

所以我相信您想要实现的是在Repository 中表示以下数据模型,如下所示:

|
|-- Country1  
|   |
|   |------- Province1
|   |------- Province2
|   |------- Province3
|-- Country2
    |
    |------- Province4
    |------- Province5
    |------- Province6

要在存储库定义中实现这一点,您可能应该使用set 而不是list。文档指出:

multi-column-name 属性确保保持多值的顺序。 multi-column-name 属性指定的列用于数据类型数组、映射和列表的多值属性,而不用于集合(无序)。对于地图类型属性,多列名称属性指定的列中的值必须是字符串。 对于列表或数组类型的属性,这些值应该是整数或数值类型,并且必须是连续的。

要实现这一点,您对 Country 的存储库定义应如下所示:

<item-descriptor display-name-resource="Country"  use-id-for-path="false" content="false" writable="true" default="true" display-property="name" folder="false" cache-mode="simple" id-separator=":" name="country" >
    <table shared-table-sequence="1" name="COUNTRY" id-column-name="id" type="primary">
        <property readable="true" queryable="true"  hidden="false" backing-map-property="false" name="id" column-name="ID" data-type="string" required="true" writable="true"/>
        <property readable="true" queryable="true" display-name="Name" cache-mode="inherit" backing-map-property="false" name="name" column-name="DISPLAY_NAME" data-type="string" required="true" writable="true"/>
    </table>
    <table shared-table-sequence="1" name="COUNTRY_PROVINCE" id-column-names="COUNTRY_ID" type="multi">
        <property readable="true" display-name-resource="provinces" data-type="set" component-item-type="province" required="false" writable="true" queryable="true" cache-mode="inherit" backing-map-property="false" name="provinces" column-name="PROVINCE_ID"/>
    </table>
</item-descriptor>

省存储库定义如下所示:

<item-descriptor display-name-resource="Province" default="false" expert="false" display-property="name" folder="false"  id-separator=":" name="province" use-id-for-path="false" content="false" writable="true">
    <table shared-table-sequence="1" name="Province" id-column-name="id" type="primary">
        <property readable="true" queryable="true" expert="false" hidden="false" cache-mode="inherit" backing-map-property="false" name="id" column-name="ID" data-type="string" required="true" writable="true"/>
        <property readable="true" queryable="true" expert="false" hidden="false" display-name="Name" cache-mode="inherit" backing-map-property="false" name="name" column-name="DISPLAY_NAME" data-type="string" required="true" writable="true"/>
    </table>
</item-descriptor>

更多信息可以在Oracle Commerce Documentation 中找到。

【讨论】:

  • 我仍然遇到同样的异常,set, 在语句上:item.getPropertyValue("provinces") 迭代结果的正确方法是什么?
  • 我试过类似的东西:java.util.Set set = (java.util.Set) item.getPropertyValue("provinces");
  • 在您的示例中,我不明白您为什么使用 3 个表:COUNTRY、COUNTRY_PROVINCE 和 Province。我认为 COUNTRY_PROVINCE 没有必要
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-18
  • 2011-06-13
  • 2021-04-06
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多