Message:
The following issue has been closed.
Resolver: Gavin King
Date: Sat, 21 Jun 2003 3:14 AM
Ah. you threw me off by saying the two queries were equivalent. If you check your SQL, you will find that they are not. The criteria query is doing a bunch of outerjoin fetching that the other is not. You will see the same exception if you add a fetch clause to the HQL.
Anyway, the exception is a well-known problem that occurs only with non-lazy collections. It is one that we will not be fixing because of performance considerations. This is in the Hibernate FAQ.
Make the collection lay and the problem disappears. If you want to fetch it more aggressively, use HQL with a FETCH clause to fetch the collection by outerjoin.
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-136
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-136
Summary: Criteria api appears to add elements to a SortedSet before setting their properties
Type: Bug
Status: Closed
Priority: Major
Resolution: WON'T FIX
Project: Hibernate2
Components:
core
Versions:
2.0 final
Assignee: Gavin King
Reporter: Paul Rivers
Created: Sat, 14 Jun 2003 4:16 PM
Updated: Sat, 21 Jun 2003 3:14 AM
Environment: Eclipse 2.1, Tomcat4.1.24, jdk1.4.1_03
Description:
As I understand it, this query by criteria query:
Criteria criteria = session.createCriteria(EntryDAO.class);
criteria.setFirstResult(rangeStart);
criteria.setMaxResults(rangeSize);
criteria.addOrder(Order.desc("dateCreated"));
entries = criteria.list();
Should return the same results as this one:
Query query = session.createQuery("from EntryDAO order by dateCreated desc");
query.setFirstResult(rangeStart);
query.setMaxResults(rangeSize);
entries = query.list();
The problem is that the normal (second) query executes fine, but the Criteria (first) query throws a NullPointerException. Each entry has a SortedSet of Categories (It's specified in the mapping file). The stack trace for the null pointer exception leads to this line:
result = this.getName().compareTo(otherCategory.getName());
In this function:
public int compareTo(Object o) {
int result;
CategoryDAO otherCategory = (CategoryDAO) o;
result = this.getDisplayIndex() - otherCategory.getDisplayIndex();
if(result == 0) {
result = this.getName().compareTo(otherCategory.getName());
}
return result;
}
The problem appears to be, to me, that for some reason the Criteria API 1. does the database query, 2. adds the new object to the SortedSet, 3. THEN sets it's properties, where it should be 1. doing the query 2. setting the properties, 3. then adding the category to the sortedset.
PLEASE let me know if there's anything I can do to help with the issue, or if there's any other information you would like. Thanks.
---------------------------------------------------------------------
JIRA INFORMATION:
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/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|