Skip to content
Advertisement

Execute sql native query from two entity using jpa or hibernate

I have 2 tables, salesOrder with column “id”, “customerId”, “textReview(boolean)” and table SalesOrderline with column “salesOrderId”, “productId”. i want to change boolean data in textReview column. I got data from the client in the form is customerId and productId.

Native Query SQL that I made like this.

update sales order set text_review = true where (select id from salesorder where customer_id = ?) in (select salesorder_id from salesorderline where product_id = ?)

Is the SQL query correct?

I’m confused how to execute this query using jpa or hibernate in spring boot.

Advertisement

Answer

In SQL should be something like:

update salesOrder

set text_review = true where customer_id = ?

and id in (select salesorder_id from salesorderline where product_id = ?)

In JPA I don’t think you need the select statement.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement