1
,我們可以創建使用@NamedNativeQuery update語句,命名原生查詢,執行更新語句
@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執行更新語句或者這是不可能的?
難道你看這 ( http://stackoverflow.com/questions/13278544/returning-a-numeric-value-with-hibernate-namednativequery) –
@vinit [使用Hibernate NamedNativeQueries返回值] -prajapati並且還請更正您的更新查詢。它應該像'UPDATE table_name SET properties WHERE clause' –