1

If i run the following query:

... AND :user MEMBER OF c.owners AND ...

it works fine, but if I add the following condition to it like

...AND ( :user MEMBER OF c.owners OR ( :user MEMBER OF c.department.members AND c.confidential = false ) ) AND ...

It doesn't give back the result i want (like the previous query). Any idea why?

EDIT

Here are the relevant part of the generated query (the whole query is the same but these parts)

With this I get back the records I want

and ( ? in ( select owners1_.owner_id from contract_owner owners1_ where contract0_.id=owners1_.contract_id ) )

With this i din't get is back

and ( ? in ( select owners1_.owner_id from contract_owner owners1_ where contract0_.id=owners1_.contract_id ) or ( ? in ( select sysuser3_.sysuser_id from department_sysuser sysuser3_ where department2_.id=sysuser3_.department_id ) ) and contract0_.confidential=0 )

EDIT2:

In the first snippet i get back 1 record (dev data only, in prod it would be more), and in the second part i want to get back the same record, but it doesn't give it back.

The user is the owner of the contract.

aBnormaLz
  • 809
  • 6
  • 22
  • Please enable [sql logging](http://stackoverflow.com/questions/2536829/hibernate-show-real-sql/2536835#2536835) and post the generated query. – Dragan Bozanovic Mar 17 '16 at 17:55
  • @DraganBozanovic Added the generated queries – aBnormaLz Mar 21 '16 at 17:52
  • Is the second snippet what you get back (in the second case) or what you want to get back? If it's what you want, please post what you do get. – WPrecht Mar 21 '16 at 18:01
  • @WPrecht-AB3RY answered your question in 'EDIT2' – aBnormaLz Mar 21 '16 at 18:20
  • Assuming the second snippet is cut and paste of what you are generating, it looks like the final AND clause (and contract0_.confidential=0) is on the wrong side of the enclosing param of the OR. So you might seed the JPA with more params to force the generator to group them the way you want. – WPrecht Mar 21 '16 at 18:31

0 Answers0