2014-05-09 41 views
0

我有一個如下所示的實體,有兩個表由註釋@SecondaryTable映射。 PrimaryKey的兩個表的名稱都是'resource_id'。當我執行HQL時Hibernate:執行HQL時使用@SecondaryTable註釋執行HQL刪除時出現含糊不清的錯誤

delete AssetProjectProposalInfoEntity e where e.resourceId=:rid 

列含糊不清的錯誤發生。

import ... 

@Entity 
@Table(name = "ASSET_PROJECT_INFO", schema = "CORE_WAC") 
@SecondaryTable(name="ASSET_PROJECT_PROPOSAL_INFO", schema="CORE_WAC") 
public class AssetProjectProposalInfoEntity 
{ 
    @Id 
    @Column(name = "RESOURCE_ID") 
    @GeneratedValue(generator="UUIdentifier") 
    @GenericGenerator(name="UUIdentifier", strategy = "uuid") 
    private String resourceId; 

    @Column(name = "PROJECT_NAME") 
    private String projectName; 


    @Column(table="ASSET_PROJECT_PROPOSAL_INFO", name="PROJECT_TYPE") 
    private String projectType; 


    @Column(table="ASSET_PROJECT_PROPOSAL_INFO", name="APPLY_UNIT_ID") 
    private String applyUnitId; 
    ... 

} 

控制檯日誌如下所示。它顯示SQL中的where子句是RESOURCE_ID =? ,但它應該是assetproje0_.RESOURCE_ID =?我認爲。任何身體可以幫助嗎?謝謝:)

Hibernate: insert into HT_ASSET_PROJECT_INFO select assetproje0_.RESOURCE_ID as 
RESOURCE_ID from CORE_WAC.ASSET_PROJECT_INFO assetproje0_ left outer join 
CORE_WAC.ASSET_PROJECT_PROPOSAL_INFO assetproje0_1_ on 
assetproje0_.RESOURCE_ID=assetproje0_1_.RESOURCE_ID where RESOURCE_ID=? 

Hibernate: delete from HT_ASSET_PROJECT_INFO 
+0

是你的表映射的正確的方式?如果是這樣,有點令人困惑:AssetProjectProposalInfoEntity作爲主表映射到ASSET_PROJECT_INFO,而作爲輔助表映射到ASSET_PROJECT_PROPOSAL_INFO ??? –

+0

@AlanHay嗨,我是新手在休眠。我使用'SecondaryTable'通過註解方法在一個實體中映射了兩個表。 ASSET_PROJECT_INFO表通過整個應用程序存儲公共信息,還有許多其他表,如ASSET_PROJECT_PROPOSAL_INFO表與ASSET_PROJECT_INFO表關聯。所以我用這種方法將ASSET_PROJECT_INFO表映射到其他表。這意味着我將擁有爲ASSET_PROJECT_INFO表和其他表之間的每個關聯創建的許多實體。我不確定這是否正確。 –

+0

我終於把session.delete(實體)而不是使用HQL –

回答

0

使用兩名當地人詢問

String deleteTable2 = 
      "DELETE CORE_WAC.ASSET_PROJECT_PROPOSAL_INFO act where RESOURCE_ID IN (:resourceIdsList)"; 
    Query qDeleteTable2 = getEntityManager().createNativeQuery(deleteTable2); 
    qDeleteTable2.setParameter("resourceIdsList", resourceIdsList); 
    qDeleteTable2.executeUpdate(); 

    String deleteTable1 = 
      "DELETE CORE_WAC.ASSET_PROJECT_INFO act where RESOURCE_ID IN (:resourceIdsList)"; 
    Query qDeleteTable1 = getEntityManager().createNativeQuery(deleteTable1); 
    qDeleteTable1.setParameter("resourceIdsList", resourceIdsList); 
    qDeleteTable1.executeUpdate();