A more complete bug report:
Tested with Hibernate 3.2.5 & 3.2.6 + MySQL 5.0.32:
in the following example "RoleNotification" has a Set of Strings (Set<String>) called "notificationRoles".
HQL:
Code:
// Find all role notifications that have Supervisor within their notificationRoles.
"FROM RoleNotification WHERE 'Supervisor' IN elements(notificationRoles)"
AST DUMP:
Code:
10:33:21,687 DEBUG AST:266 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'FROM'
| \-[RANGE] 'RANGE'
| \-[IDENT] 'RoleNotification'
\-[WHERE] 'WHERE'
\-[IN] 'in'
+-[QUOTED_STRING] ''Supervisor''
\-[IN_LIST] 'inList'
\-[ELEMENTS] 'elements'
\-[IDENT] 'notificationRoles'
Code:
10:33:21,750 DEBUG AST:232 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (pm_notifications_role,pm_notifications,pm_notifications_role_roles)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'rolenotifi0_.notification_id as id13_' {FromElement{explicit,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=pm_notifications_role,tableAlias=rolenotifi0_,origin=null,colums={,className=RoleNotification}}}
| \-[SQL_TOKEN] SqlFragment: 'rolenotifi0_1_.time as time13_, rolenotifi0_1_.priority as priority13_, rolenotifi0_1_.message as message13_'
+-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=2, fromElementByClassAlias=[], fromElementByTableAlias=[notificati1_, rolenotifi0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[{synthetic-alias}.notificationRoles], impliedElements=[]}
| +-[FROM_FRAGMENT] FromElement: 'pm_notifications_role rolenotifi0_ inner join pm_notifications rolenotifi0_1_ on rolenotifi0_.notification_id=rolenotifi0_1_.id' FromElement{explicit,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=pm_notifications_role,tableAlias=rolenotifi0_,origin=null,colums={,className=RoleNotification}}
| \-[FROM_FRAGMENT] ImpliedFromElement: '' ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=RoleNotification.notificationRoles,tableName={none},tableAlias=notificati1_,origin=pm_notifications_role rolenotifi0_ inner join pm_notifications rolenotifi0_1_ on rolenotifi0_.notification_id=rolenotifi0_1_.id,colums={,className=null}}
\-[WHERE] SqlNode: 'WHERE'
\-[IN] InLogicOperatorNode: 'in'
+-[QUOTED_STRING] LiteralNode: ''Supervisor''
\-[IN_LIST] SqlNode: 'inList'
\-[SQL_TOKEN] CollectionFunction: 'select notificati1_.role_name from pm_notifications_role_roles notificati1_ where rolenotifi0_.notification_id=notificati1_.notification_id' {method=elements,selectColumns=[select notificati1_.role_name from pm_notifications_role_roles notificati1_ where rolenotifi0_.notification_id=notificati1_.notification_id],fromElement=notificati1_}
\-[DOT] DotNode: '{non-qualified-property-ref}' {propertyName=notificationRoles,dereferenceType=3,propertyPath=notificationRoles,path={synthetic-alias}.notificationRoles,tableAlias=notificati1_,className=null,classAlias=null}
+-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}}
\-[IDENT] IdentNode: 'notificationRoles' {originalText=notificationRoles}
SQL Executed:
Code:
SELECT rolenotifi0_.notification_id AS id13_, rolenotifi0_1_.time AS time13_, rolenotifi0_1_.priority AS priority13_, rolenotifi0_1_.message AS message13_
FROM pm_notifications_role rolenotifi0_
INNER JOIN pm_notifications rolenotifi0_1_ ON rolenotifi0_.notification_id = rolenotifi0_1_.id
WHERE 'Supervisor'
IN (
SELECT notificati1_.role_name
FROM pm_notifications_role_roles notificati1_
WHERE rolenotifi0_.notification_id = notificati1_.notification_id
)
Correctly returns 1 row through PHP myadmin, yet creates zero objects through hibernate.
Now with the other query ("not in"):
HQL:
Code:
// Find all role notifications that have Supervisor within their notificationRoles.
"FROM RoleNotification WHERE 'Supervisor' NOT IN elements(notificationRoles)"
AST DUMP:
Code:
10:41:32,843 DEBUG AST:266 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'FROM'
| \-[RANGE] 'RANGE'
| \-[IDENT] 'RoleNotification'
\-[WHERE] 'WHERE'
\-[NOT_IN] 'not in'
+-[QUOTED_STRING] ''Supervisor''
\-[IN_LIST] 'inList'
\-[ELEMENTS] 'elements'
\-[IDENT] 'notificationRoles'
Code:
10:41:32,921 DEBUG AST:232 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (pm_notifications_role,pm_notifications,pm_notifications_role_roles)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'rolenotifi0_.notification_id as id13_' {FromElement{explicit,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=pm_notifications_role,tableAlias=rolenotifi0_,origin=null,colums={,className=RoleNotification}}}
| \-[SQL_TOKEN] SqlFragment: 'rolenotifi0_1_.time as time13_, rolenotifi0_1_.priority as priority13_, rolenotifi0_1_.message as message13_'
+-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=2, fromElementByClassAlias=[], fromElementByTableAlias=[notificati1_, rolenotifi0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[{synthetic-alias}.notificationRoles], impliedElements=[]}
| +-[FROM_FRAGMENT] FromElement: 'pm_notifications_role rolenotifi0_ inner join pm_notifications rolenotifi0_1_ on rolenotifi0_.notification_id=rolenotifi0_1_.id' FromElement{explicit,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=pm_notifications_role,tableAlias=rolenotifi0_,origin=null,colums={,className=RoleNotification}}
| \-[FROM_FRAGMENT] ImpliedFromElement: '' ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=RoleNotification.notificationRoles,tableName={none},tableAlias=notificati1_,origin=pm_notifications_role rolenotifi0_ inner join pm_notifications rolenotifi0_1_ on rolenotifi0_.notification_id=rolenotifi0_1_.id,colums={,className=null}}
\-[WHERE] SqlNode: 'WHERE'
\-[NOT_IN] InLogicOperatorNode: 'not in'
+-[QUOTED_STRING] LiteralNode: ''Supervisor''
\-[IN_LIST] SqlNode: 'inList'
\-[SQL_TOKEN] CollectionFunction: 'select notificati1_.role_name from pm_notifications_role_roles notificati1_ where rolenotifi0_.notification_id=notificati1_.notification_id' {method=elements,selectColumns=[select notificati1_.role_name from pm_notifications_role_roles notificati1_ where rolenotifi0_.notification_id=notificati1_.notification_id],fromElement=notificati1_}
\-[DOT] DotNode: '{non-qualified-property-ref}' {propertyName=notificationRoles,dereferenceType=3,propertyPath=notificationRoles,path={synthetic-alias}.notificationRoles,tableAlias=notificati1_,className=null,classAlias=null}
+-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}}
\-[IDENT] IdentNode: 'notificationRoles' {originalText=notificationRoles}
SQL Executed:
Code:
SELECT rolenotifi0_.notification_id AS id13_, rolenotifi0_1_.time AS time13_, rolenotifi0_1_.priority AS priority13_, rolenotifi0_1_.message AS message13_
FROM pm_notifications_role rolenotifi0_
INNER JOIN pm_notifications rolenotifi0_1_ ON rolenotifi0_.notification_id = rolenotifi0_1_.id
WHERE 'Supervisor' NOT
IN (
SELECT notificati1_.role_name
FROM pm_notifications_role_roles notificati1_
WHERE rolenotifi0_.notification_id = notificati1_.notification_id
)
Correctly returns 0 zeros through PHP myadmin, yet creates the object in hibernate.
Can I *please* get a reply on this, is this a bug, or is my HQL wrong? I'm hoping my work around holds.
Thanks again.