java - JPQL - Update with Multiple where conditions -


does jpql support following update?

update person p set p.name = :name_1 p.id = :id_1,                     p.name = :name_2 p.id = :id_2,                     p.name = :name_3 p.id = :id_3 

if not, there alternatives? tried myself. createquery returned null.

case expression supported in jpa 2.0. have provided pseudo-code, can make modifications accordingly.

  • you can try below jpql query using case.

    update person p set p.name = case when (p.id = :id1) :name_1 when (p.id = :id2) :name_2 when (p.id = :id3) :name_3 end

    general_case_expression::= case when conditional_expression scalar_expression else scalar_expression end

  • else, can try criteria api build query.

    when(expression condition, r result) : add when/then clause case expression.

    criteriabuilder.selectcase().when(criteriabuilder.equal(person.get("id"), id1), name_1);


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -