Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what it the JPQL jpa (@Query) for update column with binary operator mysql query?

SQL Query:

update de_meta set service_lines = service_lines | 5 where de_id = 20;

This works fine from SQL console.

JPA Query:

@Modifying
@Query("update DeMetaEntity set serviceLines = serviceLines | ?2 where deId = ?1")
void addDeServiceLineMap(Integer deId, int serviceLine);

This JPA query throws error because | (bitwise OR) is not valid in JPQL. Is there any way to write equivalent JPQL for given SQL query?

I don't want to use criteria queries. As I use this at JAVA INTERFACE.

like image 216
Dhaval Joshi Avatar asked Nov 27 '25 11:11

Dhaval Joshi


1 Answers

Create a native query as Alan suggested:

@Modifying
@Query("update de_meta set service_lines = service_lines | ?2 where de_id = ?1", nativeQuery=true)
void addDeServiceLineMap(Integer deId, int serviceLine);

The switch nativeQuery=true will execute the SQL query as it is.

like image 140
Simon Martinelli Avatar answered Nov 29 '25 01:11

Simon Martinelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!