Hello,
I'm using QueryDSL to access my database via Hibernate (JPA). QueryDSL generates the following JPQL which itself is translated to a wrong SQL query.
JPQLCode:
select
qtCharacteristicHeaderMapping,
qtCharacteristicHeader.tblLanguageKey.varKey,
qtCharacteristicHeader.intOrder,
qtCharacteristicGroup.intCharacteristicGroupId,
qtCharacteristicGroup.tblLanguageKey.varKey,
qtCharacteristic.intCharacteristicId,
qtCharacteristic.tblLanguageKey.varKey,
qtCharacteristic.tblFieldType.intFieldTypeId
from
TblCharacteristicHeaderMapping qtCharacteristicHeaderMapping
inner join qtCharacteristicHeaderMapping.tblComponentTypeCharacteristicHeader as qtComponentTypeCharacteristicHeader
inner join qtComponentTypeCharacteristicHeader.tblCharacteristicHeader as qtCharacteristicHeader
left join qtCharacteristicHeaderMapping.tblCharacteristicGroup as qtCharacteristicGroup
inner join qtCharacteristicHeaderMapping.tblCharacteristic as qtCharacteristic
where
qtCharacteristicHeader.intHeaderType = ?1
order by
qtCharacteristicGroup.intOrder asc
SQLCode:
select
tblcharact0_.intCharacteristicHeaderMappingID as col_0_0_,
tbllanguag5_.varKey as col_1_0_,
tblcharact3_.intCharacteristicGroupID as col_2_0_,
tbllanguag6_.varKey as col_3_0_,
tblcharact4_.intCharacteristicID as col_4_0_,
tbllanguag7_.varKey as col_5_0_,
tblcharact4_.intFieldTypeID as col_6_0_,
tblcharact0_.intCharacteristicHeaderMappingID as intChara1_3498_,
tblcharact0_.intCharacteristicID as intChara2_3498_,
tblcharact0_.intCharacteristicGroupID as intChara3_3498_,
tblcharact0_.intComponentTypeCharacteristicHeaderID as intCompo4_3498_
from
DB.dbo.tblCharacteristicHeaderMapping tblcharact0_
inner join
DB.dbo.tblComponentTypeCharacteristicHeader tblcompone1_
on tblcharact0_.intComponentTypeCharacteristicHeaderID=tblcompone1_.intComponentTypeCharacteristicHeaderID
inner join
DB.dbo.tblCharacteristicHeader tblcharact2_
on tblcompone1_.intCharacteristicHeaderID=tblcharact2_.intCharacteristicHeaderID,
dbo.tblLanguageKey tbllanguag5_
left outer join
DB.dbo.tblCharacteristicGroup tblcharact3_
on tblcharact0_.intCharacteristicGroupID=tblcharact3_.intCharacteristicGroupID,
dbo.tblLanguageKey tbllanguag6_
left outer join
DB.dbo.tblCharacteristic tblcharact4_
on tblcharact0_.intCharacteristicID=tblcharact4_.intCharacteristicID,
dbo.tblLanguageKey tbllanguag7_
where
tblcharact2_.intLanguageContentID=tbllanguag5_.intLanguageContentID
and tblcharact3_.intLanguageContentID=tbllanguag6_.intLanguageContentID
and tblcharact4_.intLanguageContentID=tbllanguag7_.intLanguageContentID
and tblcharact2_.intHeaderType=?
order by
tblcharact3_.intOrder asc
The error of the MSSQL12 server:
Code:
Msg 4104, Level 16, State 1, Line 24
The multi-part identifier "tblcharact0_.intCharacteristicGroupID" could not be bound.
Msg 4104, Level 16, State 1, Line 28
The multi-part identifier "tblcharact0_.intCharacteristicID" could not be bound.
The reason for this errors is the wrong FROM clause, which contains multiple tblLanguageKey references, but at the wrong position. They must be at the end of the FROM clause, not between the JOINS. Do you have any Idea in which version this was fixed or if this is still an error? I can't find any information and I', unable to test a newer Hibernate version.
Thanks.