[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1950) ClassCastException when using Hibernates DetachedCriteria
Christian Pietsch (JIRA)
jira-events at lists.jboss.org
Sat Sep 22 18:03:10 EDT 2007
[ http://jira.jboss.com/jira/browse/JBSEAM-1950?page=comments#action_12378227 ]
Christian Pietsch commented on JBSEAM-1950:
-------------------------------------------
Maybe I'm doing something crazy. I have a huge resultset (>50.000 objects) and I only want to get 50 objects per page (using criterias maxrows and firstrow). But I also want to display the correct number of total records (e.g. 145.000).
The overall idea behind my source is the following: Create a DetachedCriteria with all restrictions and put it in Class ActiveSearchFilter and also set the requested page number there. Then execute:
1. create a copy of my detachedCriteria (suing above copy method)
2. add a projection to my copied detachedcriteria: setProjection(Projections.rowCount()) - to get the total row count
3. execute the original detachedcriteria in ActiveSearchFilter
So maybe this is not a seam bug but a bug in my code (but this worked fine in 1.3.0Alpha).
Here is the relevant code:
public abstract class AbstractSearch implements PageableSearch {
@In
org.hibernate.Session hibernateSession;
...
public List<Object> retrieveItems(ActiveSearchFilter filter) {
if (!filter.isRowCountAvailable()) {
Criteria c = filter.getCopiedCriteria().getExecutableCriteria(
hibernateSession);
c.setProjection(Projections.rowCount());
List<Object> l = (List<Object>) c.list();
filter.setTotalSearchResults((Integer) l.get(0));
}
Criteria c = filter.getOriginalCriteria().getExecutableCriteria(
hibernateSession);
if (filter.getMaxRows() != null && filter.getMaxRows() > 0)
c.setMaxResults(filter.getMaxRows());
c.setFirstResult(filter.getFirstRow() - 1);
return c.list();
}
}
public class ActiveSearchFilter implements Serializable {
private DetachedCriteria originalCriteria;
private Integer totalSearchResults;
private Integer firstRow;
private Integer maxRows;
...
protected DetachedCriteria copy(DetachedCriteria criteria) {
try {
ByteArrayOutputStream baostream = new ByteArrayOutputStream();
ObjectOutputStream oostream = new ObjectOutputStream(baostream);
oostream.writeObject(criteria);
oostream.flush();
oostream.close();
ByteArrayInputStream baistream = new ByteArrayInputStream(baostream
.toByteArray());
ObjectInputStream oistream = new ObjectInputStream(baistream);
DetachedCriteria copy = (DetachedCriteria) oistream.readObject();
oistream.close();
return copy;
} catch (Throwable t) {
throw new HibernateException(t);
}
}
> ClassCastException when using Hibernates DetachedCriteria
> ---------------------------------------------------------
>
> Key: JBSEAM-1950
> URL: http://jira.jboss.com/jira/browse/JBSEAM-1950
> Project: JBoss Seam
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.0.0.CR1, 2.0.0.BETA1
> Environment: Jboss 4.2.1
> Reporter: Christian Pietsch
> Assigned To: Emmanuel Bernard
> Priority: Critical
>
> Since migration to Seam 2 (tried Beta 1 and CR1) I cannot list my entities using Hibernate's DetachedCriteria any longer. Stack trace is:
> Caused by: java.lang.ClassCastException: org.hibernate.search.impl.FullTextSessionImpl
> at org.jboss.seam.persistence.HibernateSessionProxy.getDelegateSessionImplementor(HibernateSessionP
> roxy.java:401)
> at org.jboss.seam.persistence.HibernateSessionProxy.list(HibernateSessionProxy.java:566)
> at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
> at de.dvdb.generic.search.AbstractSearch.retrieveItems(AbstractSearch.java:261)
> - in general I can access the entityManager in my application
> - I don't use Seam's new search capabilities at all (right now)
> - I'm getting the Hibernate Session in the following way:
> <factory name="hibernateSession" scope="STATELESS"
> auto-create="true" value="#{dvdb.delegate}" />
> <persistence:managed-persistence-context name="dvdb"
> auto-create="true"
> persistence-unit-jndi-name="java:/dvdbEntityManagerFactory" />
> Adding hibernate-search.jar and dependencies didn't help.
> - Chris
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list