From: Emmanuel B. (JIRA) <no...@at...> - 2006-06-15 00:26:34
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1632?page=all ] Emmanuel Bernard reopened HHH-1632: ----------------------------------- > Problem using Expression.isNull and Expression.isNotNull in a Criteria with an entity with a composite id. > ---------------------------------------------------------------------------------------------------------- > > Key: HHH-1632 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1632 > Project: Hibernate3 > Type: Bug > Components: query-criteria > Versions: 3.1.3 > Environment: Hibernate 3.1.3, DB2 > Reporter: Jean-Francois Lagace > Priority: Blocker > Attachments: NullAndNotNullExpressionPatch.txt > > > I have found a problem using Expression.isNull and Expression.isNotNull in a Criteria with composite primary keys. > We have the following 2 tables: > Table1 have a primary key composed of column A and column C. > Table2 have a primary key composed of column B and column C. And it has also a foreign key from Table1 (column A and C). The column C has always the same value in Table1 and Table2, so it's not repeated twice in Table2 (for the foreign key). So the Table2 has 3 columns: B, C and A. > When using Criteria to select every row from Table2 for which the link to Table1 is null, I write the following code: > Criteria criteria = session.createCriteria(Table2.class); > criteria.add(Expression.isNull("table1")); > List<Table2> list = criteria.list(); > The generated SQL looks like this: > select * from Table2 where (A is null and C is null) > This request returns all rows from Table2 because the column C is never null. I think the where clause should have been written using an OR instead of an AND. If one column of the foreign key is null, the link with Table1 should be considered as null. > And there is the same problem with the isNotNull expression too. But in that case, the where clause is written using an OR instead of an AND. > To fixed those problems, I replaced the OR by an AND in the toSqlString method of the class org.hibernate.criterion.NotNullExpression. I did the same in the class org.hibernate.criterion.NullExpression, replacing the AND by an OR. -- 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 |