2013-08-05 58 views
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執行更新語句或者這是不可能的?

+1

難道你看這 ( http://stackoverflow.com/questions/13278544/returning-a-numeric-value-with-hibernate-namednativequery) –

+0

@vinit [使用Hibernate NamedNativeQueries返回值] -prajapati並且還請更正您的更新查詢。它應該像'UPDATE table_name SET properties WHERE clause' –

回答

2

嘗試加入@NamedNativeQuery(resultClass = ConversionChecker.class)

+0

你能提供更多的細節嗎? –