0

I am new to JPA and need assistance writing following query. I am on wildfly, javaEE with hibernate behind etc etc.. The idea is to have a where inside my select statement with two conditions. The first condition shall be matched first against all rows and then in case nothing is found the second one shall be matched against all rows.

for example (pseudo code):

select * from myTable
where (con1) and (if no con1 try match con2)

rows matching con1 shall be returned because con1 has prio

rows matching both conditions shall never be returned

how to write such a query in jpa 2.1? thanks in advance

Niki
  • 85
  • 1
  • 6

1 Answers1

0

select * from myTable where (CON1) OR (CON2)

Edit: the above might not be correct. You should probably use the case statement:

If you need it, I suggest a Case statement:

Where Case when Expr1 then Expr2 else Expr3 end = desiredResult

as in https://stackoverflow.com/a/12320806/7913706

vortigern
  • 49
  • 6