2011-11-29 30 views
0

鏈接的存儲我有,我有employeeABC庫 和XYZaddress_details兩個表的要求。將數據插入到在ATG

employee的一列有對address_details的外鍵引用。

在這裏,我遇到的primaryKeyaddress_details,並與primaryKey 參考我必須插入employee我的數據。

所以我RDF是這樣的:

RDF 1:(Repository1:ABC

<item-descriptor name=」employee」 > 
<table name=」employee」> 
    <property name=」empId」 data-type=」string」 column-name=」emp_id」 
    required=」true」/> 
    <property name=」address」 column-name=」address_id」 item-type=」address」 
    repository=」XYZ」 required=」true」/> 
</table> 
</item-descriptor> 

RDF 2:(Repsitory2:XYZ

<item-descriptor name=」address」 > 
    <table name=」address_details」> 
    <property name=」addressId」 data-type=」string」 column-name=」address_id」/> 
    <property name=」streetName」 column-name=」street_name」 data-type=」string」/> 
    <property name=」city」 column-name=」city」 data-type=」string」 /> 
    </table> 
</item-descriptor> 

我所有的存儲在表address_details中的地址。我必須 地圖employee到這些地址。

這我想這裏的方式獲取的RepostoryItemAddress 第一,然後設置的employee財產型address並將其添加到 表employee。這工作。

但是我想在一個呼叫中單獨插入employee數據?

關於如何使用RepositoryItemMutableRepositoryItem

+0

爲什麼你需要在一次通話中關聯?它的理由是,如果你想關聯這兩個,你必須先查找你想要關聯的項目,然後執行關聯。首先進行必要的查找並在找到適當的地址項目後更新員工項目沒有任何問題。 – chrisjleu

回答

0

通過插入一個調用,我假設你的意思是你想要提交所有的插入原子。沒有機制在一個SQL語句中執行多次插入 - 您必須爲您創建的每個項目調用一次MutableRepository.addItem()。以下代碼將允許您將存儲庫工作包裝在事務中,以便數據全部立即提交。

TransactionManager tm = ... 
TransactionDemarcation td = new TransactionDemarcation(); 
try { 
    try { 
    td.begin(tm); 

    // Create all items and call MutableRepository.addItem() for each of them. 
    } 
    finally { 
    td.end(); 
    } 
} 
catch (TransactionDemarcationException exc) { 
    logError(exc); 
}