0

我有一个如下所示的实体,注释@SecondaryTable 映射了两个表。两个表的 PrimaryKey 的名称都是'resource_id'。当我执行 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
4

1 回答 1

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();
于 2016-12-22T08:52:51.003 回答