Hi,
I have the following HQL query:
Code:
SELECT
DISTINCT co.mpsId
FROM
com.example.search.SearchCase co
WHERE
EXISTS (
FROM
co.g2s t0
WHERE
(
EXISTS (
SELECT
sa
FROM
t0.g2Multi sa
WHERE
sa = :hp0
)
)
(the hp0 parameter would be set to a String value)
So, starting from the top, SearchCase has a list called 'g2s':
Code:
<list name="g2s" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`SEARCHCASE_G2S_MPSID`" not-null="false" unique="false"/>
</key>
<list-index column="`SEARCHCASE_G2S_IDX`"/>
<one-to-many entity-name="com.example.search.Global2"/>
</list>
As you can see, it's a list of Global2 objects. Global2 then contains a list of Strings called 'g2Multi':
Code:
<list name="g2Multi" table="`MPS_1_SERCH_GLOBAL2G2MULTI`" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`GLOBAL2_G2MULTI_MPSID`" not-null="true" unique="false"/>
</key>
<list-index column="`GLOBAL2_G2MULTI_IDX`"/>
<element type="java.lang.String" not-null="false" unique="false">
<column not-null="false" unique="false" name="`G2MULTI`" length="400"/>
</element>
</list>
To summarize, SearchCase contains a list of Global2 objects ('g2s'); Each Global2 object contains a list of Strings ('g2Multi').
A problem occurs when this gets converted to SQL.
Notice the empty FROM clause ("from where") in the first sub-query:
Code:
select
distinct searchcase0_.[MPS_ID] as col_0_0_
from
[MPS_1_SERCH_SEARCHCASE] searchcase0_
where
exists (
select
g2s1_.[MPS_ID]
from
where
searchcase0_.[MPS_ID]=g2s1_.[SEARCHCASE_G2S_MPSID]
and (
exists (
select
g2multi2_.[G2MULTI]
from
[MPS_1_SERCH_GLOBAL2G2MULTI] g2multi2_
where
g2s1_.[MPS_ID]=g2multi2_.[GLOBAL2_G2MULTI_MPSID]
and g2multi2_.[G2MULTI]=?
)
)
)
Can anyone immediately spot why this is going wrong? If not, I can provide more details, but didn't want to write a huge post if the detail isn't necessary.
Many thanks for any help,
Ben.