Hibernate is generating the SQL for the following query :
select pcp.id from PersistentContentProfile pcp where pcp.service.id = :service_id and exists(select 1 from Subscription s where s.contentProfile.id = pcp.id and s.status in (:statuses))
as native PostgreSQL query :
select persistent0_.id as col_0_0_
from ems.nlt_content_profile persistent0_
where
1=2 and
persistent0_.service_id=? and
(exists (select 1
from ems.nlt_subscription subscripti1_
where subscripti1_.content_profile_id=persistent0_.id and
(subscripti1_.status in (?,?))))
Observed
‘1=2’
getting appended to the query? Why is this getting added? Due to this, no records are retrieved.
I figured out it was due to a configuration mistake. I was using @ForceDiscriminator and only the abstract class was configured in persistence.xml while configuration for any concrete subsclass was missing.