I have problem with executing following query:

from Customer c where c.connectedUserID = 1 and (c.connectedFinancialAnalyst is null or c.connectedFinancialAnalyst.completed = false)

object c.connectedFinancialAnalyst can be null. What I need is to find Customers that dont have financial analyst or property in financial analyst has specific value.

Edit: completed property is boolean in postgres and in java

Output generated by Hibernate

select as id1_0_,
        customer0_.birthDate as birthDat2_0_,
        customer0_.birthPlace as birthPla3_0_, as city4_0_, as email5_0_,
        customer0_.fatherName as fatherNa6_0_,
        customer0_.motherName as motherNa7_0_, as name8_0_,
        customer0_.pesel as pesel9_0_,
        customer0_.phoneNumber as phoneNu10_0_,
        customer0_.postalCode as postalC11_0_,
        customer0_.secondName as secondN12_0_, as sex13_0_,
        customer0_.street as street14_0_,
        customer0_.surname as surname15_0_,
        customer0_.connectedFinancialAnalyst_id as connect17_0_,
        customer0_.connectedUserID as connect16_0_ 
        Customer customer0_ cross 
        FinancialAnalyst financiala1_ 
        and customer0_.connectedUserID=1 
        and (
            customer0_.connectedFinancialAnalyst_id is null 
            or financiala1_.completed='false'
¿Fue útil?


You need to be explicit that you want to do a left join

from Customer c 
left join c.connectedFinancialAnalyst as analyst
where c.connectedUserID = 1 and (analyst.completed is null or analyst.completed = false)

Otros consejos

I rewritten my code to Criteria and evrything works great. I suppose tkat the problem was with left join. When I used criteria i had to append Left Outter join like:

Criteria c = session.createCriteria(Customer.class, "c").createAlias("c.connectedFinancialAnalyst", "analyst", JoinType.LEFT_OUTER_JOIN);

Maybe when i would change left join at query to left outter join everything might work great ^^. But now my code seems to be a little bit more user friendly ^^

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top