Hibernate version: 3.0.5
Database: PostgreSQL 7.4.8
Generated SQL:
Quote:
select company0_.id as id5_, company0_.companysize as companys2_5_,
company0_.country_id as country3_5_, company0_.name1 as name4_5_,
company0_.name2 as name5_5_, company0_.address1 as address6_5_,
company0_.address2 as address7_5_, company0_.zip as zip5_, company0_.city
as city5_, company0_.phone as phone5_, company0_.fax as fax5_,
company0_.logo as logo5_, company0_.email as email5_, company0_.homepage as
homepage5_, company0_.founded as founded5_, company0_.employees as
employees5_, company0_.valid as valid5_, company0_.remark as remark5_,
company0_.created as created5_, company0_.createdby as createdby5_,
company0_.updated as updated5_, company0_.updatedby as updatedby5_,
company0_.description as descrip23_5_, company0_.desc_keys as desc24_5_
from ixtenso_owner.company company0_
where ( company0_.id in (
select distinct company1_.id
from ixtenso_owner.company company1_,
left outer join company_ref_sector sectors2_ on company1_.id=sectors2_.ref
left outer join ixtenso_owner.sector sector3_ on sectors2_.id_sector=sector3_.id,
left outer join company_ref_keyword keywords4_ on company1_.id=keywords4_.ref
left outer join ixtenso_owner.keyword keyword5_ on keywords4_.id_keyword=keyword5_.id
where ( lower(company1_.name1) like '%schilder%' or
lower(company1_.name2) like '%schilder%' or
lower(company1_.description) like '%schilder%' or
lower(company1_.desc_keys) like '%schilder%' or
lower(sector3_.value) like '%schilder%' or
lower(keyword5_.value) like '%schilder%' )
and ( sector3_.id in (1, 2))
)
)
and company0_.valid=true
order by lower(company0_.name1);
Hello,
I'm having a problem with following HQL Query:
Quote:
from Company c
where c.id in
(
select distinct(c.id)
from Company c
left join c.sectors s
left join c.keywords k
where ( lower(c.name1) like :searchText
or lower(c.name2) like :searchText
or lower(c.description) like :searchText
or lower(c.descKeys) like :searchText
or lower(s.name) like :searchText
or lower(k.name) like :searchText
)
and s.id in (:sectorId)
)
and c.valid = true
order by lower(c.name1)
This one results in the above SQL-Statement which has 2 errors, that prevent it from returning a result. The following exception is thrown:
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42601
2005-09-27 14:08:02,016 ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: syntax error at or near "outer"
As you can see there is comma in the subquery after the "from"-clause just before "left outer join" as well as one after the second "left outer join". If I remove them the query runs as expected. But how can I tune the HQL to get a proper statement?
Running the subquery on its own reveals the correct SQL-Query. So it obviously has something to do with using the statement as a subquery.
Thanks in advance