EJB-QL for "IS EMPTY" on relation table uses wrong column and is broken in 
general
----------------------------------------------------------------------------------

         Key: JBAS-1263
         URL: http://jira.jboss.com/jira/browse/JBAS-1263
     Project: JBoss Application Server
        Type: Bug
  Components: CMP service  
    Versions: JBossAS-4.0.1 Final, JBossAS-4.0.0 Final    
 Environment: JDK 1.5.0, Windows XP+SP2, MySQL, Connector/J 3.1.6
    Reporter: cgs
 Assigned to: Scott M Stark 


TemplateEJB:

 * @ejb.finder
 *     signature="java.util.Collection findPublic()"
 *     query="SELECT DISTINCT OBJECT(o)
 *         FROM template o
 *         WHERE o.organizationList IS EMPTY"

/**
 * @ejb.interface-method
 * 
 * @ejb.relation
 *     name="Organization-Template"
 *     role-name="template-belongs-to-organization"
 * 
 * @jboss.relation
 *     fk-constraint="true"
 *     fk-column="organization_id"
 *     related-pk-field="id"
 * 
 * @jboss.relation-table
 *     table-name="template_to_organization"
 */
public abstract Set getOrganizationList();
public abstract void setOrganizationList(Set organizationList);

OrganizationEJB:

/**
 * @ejb.interface-method
 * 
 * @ejb.relation
 *     name="Organization-Template"
 *     role-name="organization-has-templates"
 * 
 * @jboss.relation
 *     fk-constraint="true"
 *     fk-column="template_id"
 *     related-pk-field="id"
 * 
 * @jboss.relation-table
 *     table-name="template_to_organization"
 */
public abstract Set getTemplateList();
public abstract void setTemplateList(Set templateList);

The SQL that is generated for the finder is:

SELECT DISTINCT
    t0_o.id, t0_o.image, t0_o.image_thumbnail, t0_o.image_thumbnail_type,
    t0_o.image_type, t0_o.name, t0_o.template, t0_o.time_created,
    t0_o.time_updated, t0_o.uuid
FROM
    template t0_o,
    organization t2_o_organizationList,
    template_to_organization t1_o_organizationList_RELATION_T
WHERE (
    t1_o_organizationList_RELATION_T.template_id IS NULL AND
    t0_o.id=t1_o_organizationList_RELATION_T.template_id AND
    t2_o_organizationList.id=t1_o_organizationList_RELATION_T.organization_id
)

The first condition shouldn't be checking if ``template_id IS NULL'', but 
``organization_id IS NULL''.  Even if it properly checked organization_id, the 
query still would not work.  If a relation using a relation table has an empty 
list, the second condition is never matched.  The list is always empty and it 
cannot proceed.  (t1_o_organizationList_RELATION_T.template_id will never have 
any values in an empty relation.)


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.jboss.com/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
JBoss-Development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to