1

我们可以使用@NamedNativeQuery 创建更新语句吗?

@Entity
@Table(schema = "public", name = "conversion_checker")
@NamedNativeQueries({
    @NamedNativeQuery(name="updateExpireStatus", query="UPDATE conversion_checker SET status='Expired' FROM conversion_checker ")
})
public class ConversionChecker extends BaseEntity {...}

在这里我正在执行本机查询

/**
 * {@inheritDoc}}
 */
@Override
public int executeNativeUpdate(String namedNativeQuery, Map<String, Object> params) {
    Query query = getSession().getNamedQuery(namedNativeQuery);
    if(params!=null && params.size()>0){
        for(Map.Entry<String, Object> param: params.entrySet()){
            query.setParameter(param.getKey(), param.getValue());
        }
    }
    return query.executeUpdate();
}

它抛出,

Caused by: org.hibernate.cfg.NotYetImplementedException: Pure native scalar queries are not yet supported,

如何使用 @NamedNativeQuery 执行更新语句,否则这是不可能的?

4

1 回答 1

2

尝试添加@NamedNativeQuery( resultClass = ConversionChecker.class ).

于 2013-08-05T13:53:32.657 回答