简体   繁体   English

HQL查询未执行

[英]HQL Query not executing

I have 2 tables Asset and Asset_Dist_Types. 我有2个表Asset和Asset_Dist_Types。 Asset is parent and Asset_Dist_Types is a child table. Asset是父表,Asset_Dist_Types是子表。 Asset_Dist_Types is having 2 columns asset_id and lkp_dist_type where asset_id is the primary key in Asset table. Asset_Dist_Types具有2列asset_id和lkp_dist_type,其中asset_id是Asset表中的主键。 In Asset_Dist_Types it is a many to many (one asset_id can have multiple lkp_dist_type entries.) In java, we have entity class only for Asset table. 在Asset_Dist_Types中,它是多对多的(一个asset_id可以具有多个lkp_dist_type条目。)在Java中,我们仅对Asset表具有实体类。 In that for Asset_Dist_Type, they have mentioned it as collection of elements. 在针对Asset_Dist_Type的描述中,他们将其称为元素集合。 In Asset.java, entry for Asset_Dist_Type is as follows. 在Asset.java中,Asset_Dist_Type的条目如下。

@CollectionOfElements
    @JoinTable(name = "ASSET_DIST_TYPE", joinColumns = @JoinColumn(name="ASSET_ID"))
    @Column(name="LKP_DIST_TYPE")
    private Set<Integer> distTypes = new LinkedHashSet<Integer>(0);

Now I would like to update Asset_Dist_Type table's lkp_dist_type column. 现在,我想更新Asset_Dist_Type表的lkp_dist_type列。 I have list of asset id's. 我有资产ID的列表。 I have written following query to update it. 我写了下面的查询来更新它。

int hql = entityManager.createQuery(
     "update Asset a set a.distTypes = :distTypeParamId where a.assetId in (:assetIdParam)")
.setParameter("distTypeParamId", distTypeList)
.setParameter("assetIdParam", assetIdListToUpdateLOB)
.executeUpdate();

But this is throwing 但这是抛出

javax.persistence.PersistenceException: 
org.hibernate.exception.GenericJDBCException: could not execute update query. 

Since I am new to hibernate I am not getting what is the solution. 由于我是冬眠的新手,所以我没有解决的办法。 Can someone please help me? 有人可以帮帮我吗?

Solved it by following a different way.. I got list of asset id's and list of distribution types. 通过采用其他方法解决了此问题。.我获得了资产ID列表和分配类型列表。 I iterated over the list of asset id's and for each asset id I added list of distribution types and flushed it. 我遍历了资产ID的列表,并为每个资产ID添加了分布类型列表并刷新了它。 It is working now..! 现在正在工作..!

After getting list of asset id's 获取资产ID的列表后

    for(int i=0;i<assetIdListToUpdateLOB.size();i++){

                int assetId = assetIdListToUpdateLOB.get(i);
                System.out.println(assetId);
                List<Asset> assetDetailsList =  entityManager
                .createQuery(
                        "select distinct asset from Asset asset "
                                + "left join fetch asset.distTypes dt "
                                + "where asset.assetId = :assetIdParam")
                .setParameter("assetIdParam", assetId).getResultList();
                if(assetDetailsList.size()>0){
                this.asset = assetDetailsList.get(0);
                asset.getDistTypes().clear();
                asset.getDistTypes().addAll(selectedDistributionTypes);
                entityManager.flush();
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM