l have code snippet used to be work in Hibernate 3.1.3 , but after upgraded to Hibernate 3.2 rc3 , the code broke without any error message.
Code:
public Integer pageNodeByCriteria(BookCommand bookCommand)
throws DataAccessException {
final Book book = bookCommand.getBook();
final Author iAuthor = bookCommand.getAuthor();
final Publisher iPublisher = book.getPublisher();
final int page = bookCommand.getS_page();
final int pageSize = bookCommand.getS_pageSize();
final int ascending = bookCommand.getS_ascending();
final String sortColumn = bookCommand.getS_sortColumn();
return (Integer) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
StringBuffer queryString = new StringBuffer();
boolean conditionFound = false;
String title = book.getTitle();
String isbn = book.getIsbn();
String authorName = iAuthor.getAuthorName();
String publisherName = iPublisher.getPublisherName();
if(title != null){
queryString.append("lower(b.title) like :title ");
conditionFound=true;
}
if(isbn != null){
if (conditionFound) queryString.append("and ");
queryString.append("lower(b.isbn) like :isbn ");
conditionFound=true;
}
if (authorName != null) {
if (conditionFound) queryString.append("and ");
queryString.append("lower(a.authorName) like :authorName ");
conditionFound=true;
}
if (publisherName != null) {
if (conditionFound) queryString.append("and ");
queryString.append("lower(p.publisherName) like :publisherName ");
conditionFound=true;
}
String fromClause = conditionFound ?
"select count(*) from Book b " +
"left join b.authors a " +
"left join b.publisher p where "
:
"select count(*) from Book b " +
"left join b.authors a " +
"left join b.publisher p ";
queryString.insert(0, fromClause).append("group by b.id order by b.").append(sortColumn);
if(ascending > 0){
queryString.append(" asc");
}else{
queryString.append(" desc");
}
Query query = getSession().createQuery( queryString.toString() );
if (title != null)
query.setString( "title",'%' + title.toLowerCase() + '%' );
if (isbn != null)
query.setString( "isbn",'%' + isbn.toLowerCase() + '%' );
if (authorName != null)
query.setString( "authorName",'%' + authorName.toLowerCase() + '%' );
if (publisherName != null)
query.setString( "publisherName",'%' + publisherName.toLowerCase() + '%' );
Iterator iter = query.setFirstResult(0)
.setMaxResults((page+1) * pageSize)
.list()
.iterator();
int sum = 0;
while ( iter.hasNext() ) {
Integer count = (Integer) iter.next(); // <<<<<<<< Hibernate 3.2 broke here
sum = sum + count.intValue();
}
return new Integer(sum);
}
});
}
after some finding , l found the code broke in the
Quote:
Integer count = (Integer) iter.next();
and found the "Blocker" in the hibernate JIRA ,
http://opensource.atlassian.com/project ... e/HHH-1412the author said ,
Quote:
Collection fetches and firstResult/maxRows currently do not return logical results, since the firstResult/maxRows are applied at the database level. We need to recognize this scenario and perform the firstResult/maxRows in memory (plus generously warn the user).
but l still don't understand the problem , can any one explain me using a simple example ? Thank in advance .
moon