Hibernate - Update with Inner Join

Problem:

Perform an hibernate update  based on the results from a inner join.

Solution:

String hqlUpdate = "update Product p "
+ "set p.flowStatus = :toFlowStatus "
+ "where p.id in "
+ "(select fp.id "
+ "from OrderProduct as op "
+ "inner join op.product as p "
+ "where op.flowStatus = :orderProductFlowStatus"
+ ")";
sessionFactory.getCurrentSession().createQuery(hqlUpdate)
.setString( "toFlowStatus", toFlowStatus.getKey().toString())
.setString( "orderProductFlowStatus", feedProductDeltaFlowStatus.getKey().toString())
.executeUpdate();

Comments

Popular posts from this blog

Hibernate - HibernateException: createQuery is not valid without active transaction