我正在尝试更新DATA,但此查询使用insert

时间:2013-03-27 17:04:02

标签: hibernate java-ee spring-mvc

Query quer = sess.createQuery("update materialrate  set materialId=:MaterialId, subWorkId=:SubWorkId,unitId=:UnitId ,rate=:Rate, lastUpdatedUserId=:LastUpdatedUserId  where materialRateId=:MaterialRateId");
 quer.setInteger("materialId", n.getMaterialId());
        quer.setInteger("subWorkId", n.getSubWorkId());
        quer.setInteger("unitId", n.getUnitId());
        quer.setInteger("rate",n.getRate());
       // quer.setDate("lastUpdatedDate", current_timestamp());//lastUpdateDate=:current_timestamp() ,
        quer.setInteger("lastUpdatedUserId", n.getLastUpdatedUserId());
        quer.executeUpdate();

1 个答案:

答案 0 :(得分:1)

由于您使用的是命名参数,因此在设置这些参数时需要使用相同的名称。使用以下行替换代码:

Query quer = sess.createQuery("update materialrate  set materialId=:MaterialId, subWorkId=:SubWorkId,unitId=:UnitId ,rate=:Rate, lastUpdatedUserId=:LastUpdatedUserId  where materialRateId=:MaterialRateId");
 quer.setInteger("MaterialId", n.getMaterialId());
        quer.setInteger("SubWorkId", n.getSubWorkId());
        quer.setInteger("UnitId ", n.getUnitId());
        quer.setInteger("Rate",n.getRate());
       // quer.setDate("lastUpdatedDate", current_timestamp());//lastUpdateDate=:current_timestamp() ,
        quer.setInteger("LastUpdatedUserId ", n.getLastUpdatedUserId());
        quer.executeUpdate();