Clicky

Hibernate - Update with Inner Join

December 10, 2015

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();