[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3022) Incorrect SQL with not-equal operator '<>' on entities with composite key
Matthias Lanz (JIRA)
noreply at atlassian.com
Thu Dec 20 11:27:05 EST 2007
Incorrect SQL with not-equal operator '<>' on entities with composite key
-------------------------------------------------------------------------
Key: HHH-3022
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3022
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.4.sp1, 3.2.3
Environment: MySQL with Connector/J 5.0.6
Tested on JBoss jboss-eap-4.2cp01
Reporter: Matthias Lanz
Wrong SQL is generated when using "<>" in EJBQL on entities with composite keys.
EJB QL:
Customer c= em.find(Customer.class, [...])
query= em.createQuery("UPDATE Customer c SET [...] WHERE [...] AND c <> :customer");
query.setParameter("customer", customer);
Customer.class has a composite key with @EmbeddedId (String mand, long id)
The SQL is missing a NOT and the brackets around the composite-key condition and therefore the boolean expression is true even if one part of the composite key matches:
NOT condition1 AND NOT condition2
update CustCustomer set [...] where [...] and mand<>? and id<>?
but is has to be
NOT (condition1 AND condition2)
update CustCustomer set [...] where [...] and NOT (mand=? and id=?)
Workaround:
"UPDATE Customer c SET [...] WHERE [...] AND c NOT IN (:customer)"
which results in
(id,mand) NOT IN ((?,?))
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list