Can someone tell me why the SQL generated from this query is missing the second table declaration in the FROM clause:
<query-method>
<method-name>findByGlobalApplicationDomain</method-name>
<method-params/>
</query-method>
<ejb-ql><![CDATA[
SELECT DISTINCT OBJECT(rm)
FROM rolemodules AS rm
WHERE rm.role.applicationId IS NULL AND
rm.role.domainId IS NULL
]]></ejb-ql>
It generates the following SQL:
SELECT DISTINCT t0_rm.roleId, t0_rm.moduleId
FROM RoleModules t0_rm
WHERE t1_rm_role.applicationId IS NULL AND
t1_rm_role.domainId IS NULL
And generates the following error on the web page:
Could not obtain collection of roleModules! Find failed: java.sql.SQLException: General error: Unknown table 't1_rm_role' in where clause
Note that this query is a workaround, one of four queries created, to compensate for the lack of ability to use the following query:
<query-method>
<method-name>findByGlobalApplicationDomain</method-name>
<method-params/>
</query-method>
<ejb-ql><![CDATA[
SELECT DISTINCT OBJECT(rm)
FROM rolemodules AS rm
WHERE (rm.role.applicationId = ?1 OR
(rm.role.applicationId IS NULL AND ?1 IS NULL)) AND
(rm.role.domainId = ?2 OR
(rm.role.domainId IS NULL AND ?2 IS NULL)
]]></ejb-ql>
In this workaround the other three queries work fine. They, on the other hand, accept parameters, either ?1 or ?2 or both. This one does not need parameters, as it is known that the values are always null.
Is this a bug in JBoss' implementation of EJB-QL, or another lack of insight on the definition of the EJB-QL spec.