2016-07-07 46 views
0
public void do_UPDATE(Set<Long> customerIdSet) { 

    final String query = 
     "UPDATE product_orders po " + 
     "INNER join customer c " + 
     "ON po.order_id = c.order_id " + 
     "SET po.updated_on = now() " + 
     "WHERE c.customer_id IN (:customerIdSet)"; 

     List<Long> ids = new ArrayList<Long>(customerIdSet.size()); 

     for(final Long id : customerIdSet) { 
      ids.add(id); 
     } 

    _sessionFactory 
     .getCurrentSession() 
     .createSQLQuery(query) 
     .setParameterList("customerIdSet", ids) 
     .executeUpdate(); 

} 

我收到SQLGrammarException。这个查询实际上运行在一个真正的MySQL控制台中,但为什么Hibernate认为它是正确的语法?休眠,无法执行具有连接的本机SQL更新查询

+0

'.createQuery(查询)'? http://stackoverflow.com/questions/8636806/difference-between-hibernate-createcriteria-createquery-createsqlquery-functio – Alex

+0

这是一个用于创建HQL查询。 –

+0

'.setParameter('呢?因为你的'customerIdSet'不是'List'型 – Alex

回答

0

我的平台将不会执行与INNER声明中他们加入,因此该解决方案是使用子查询。

0

如果问题是与INNER JOIN我会尝试修改查询:

"UPDATE product_orders po " + 
"INNER join customer c " + 
"ON po.order_id = c.order_id " + 
"AND c.customer_id IN (:customerIdSet) "+ 
"SET po.updated_on = now() " 
+0

JDBC应该能够用手标准查询,我改成了使用子查询 –