We've been using Hibernate for quite some time in JLCP but we've had a problem with the paging of results in any collection. The code we're using for collection paging is the following:
List topicList = null;
Session session = null;
try
{
session = this.sessionManager.getHibernateSession();
String query = "from topic in class org.jlcp.module.forum.model.Message where topic.parentMessage is null and topic.approved=true and topic.category="+category.getId() + " order by topic.creationDate desc";
Query q = session.createFilter(topicList, query); // the trivial filter
q.setMaxResults(perPage);
// Substract one from the page so we can enter pages 1-infinity, but
// but first result is 0-(infinity-1)
q.setFirstResult(perPage * (page-1));
topicList = q.list();
}
catch (HibernateException he)
{
throw new PersistenceException(he);
}
finally
{
this.sessionManager.flushCommitCloseSession(session);
}
This code generates the following exception each time it runs:
org.jlcp.infrastructure.persistence.exceptions.PersistenceException: net.sf.hibernate.TransientObjectException: Collection was not yet persistent
at org.jlcp.module.forum.provider.hibernate.dao.CategoryDAO.getModeratedTopics(CategoryDAO.java:255)
at org.jlcp.module.forum.ForumManager.getModeratedTopics(ForumManager.java:81)
at org.jlcp.module.forum.web.taglib.topic.HasTopics.doStartTag(HasTopics.java:78)
....
Caused by: net.sf.hibernate.TransientObjectException: Collection was not yet persistent
at net.sf.hibernate.impl.SessionImpl.getFilterTranslator(SessionImpl.java:3381)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3415)
at net.sf.hibernate.impl.FilterImpl.list(FilterImpl.java:42)
at org.jlcp.module.forum.provider.hibernate.dao.CategoryDAO.getModeratedTopics(CategoryDAO.java:251)
Any help here would be great, as its really killing me!
Thanks in advance,
Matt
matt@javalobby.org