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

Oracle - duplicate fields in RECORD,TABLE or argument list are not permitted

Oracle - ORA-29282: invalid file ID, ORA-06512: at "SYS.UTL_FILE"