Logical Problem NHibernate HQL

I am trying to write an NHIBnate NHIB query that uses brackets in a where clause. However, the HQL parser seems to ignore my bracket, thereby changing the meaning of my statement. Can anyone shed some light on this question?

The following HQL query:

from WebUser u left join fetch u.WebUserProfile left join fetch 
u.CommunicationPreferences where (u.CommunicationPreferences.Email = 0 and
u.SyncDate is not null) or u.DateDeleted is not null

translates to:

from   WebUser webuser0_
left outer join WebUserProfile webuserpro1_
on webuser0_.UserId = webuserpro1_.WebUserId
left outer join WebUserCommunicationPreferences communicat2_
on webuser0_.UserId = communicat2_.UserId
where  communicat2_.Email = 0
and (webuser0_.SyncDate is not null)
or webuser0_.DateDeleted is not null

thanks

John

+3
source share
2 answers

I know this is a late answer, but I had to add my two cents.

In SQL, the and operator takes a preliminary check on the or operator. So

(u.CommunicationPreferences.Email = 0 and u.SyncDate is not null) or u.DateDeleted is not null

coincides with

communicationat2_.Email = 0 (webuser0_.SyncDate ) webuser0_.DateDeleted .

+2

, from, where. null , SQL ( HQL).

: http://en.wikipedia.org/wiki/Null_ (SQL)

u.CommunicationPreferences.Email = 0, CommunicationPreferences , .

( ):

from WebUser u 
  left join fetch u.WebUserProfile w
  left join fetch u.CommunicationPreferences c
where ( (c.Email = 0 or c is null) 
         and u.SyncDate is not null) 
or u.DateDeleted is not null

HQL :

  • (w c ), (c.Email = 0) (or c is null)

. :

LEFT , WebUser, CommunicationPreferences. u.CommunicationPreferences.Email, , u.CommunicationPreferences ( , ).

, , SQL ... HQL :-) .

0

Source: https://habr.com/ru/post/1715315/


All Articles