I'm trying to adapt a CriteriaPager I've used with the patched version of Hibernate2 to page criteria query results.
This components simply get a Criteria object, applies a RowCount projection to the query, executes it, gets the total row number for paging calculation, removes the projection, sets the MaxResults and FirstResult params and re-executes the query. When I execute the first query, I get an Exception:
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of web.model.Articolo.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:117)
at org.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:673)
at org.hibernate.persister.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:845)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:169)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:202)
at org.hibernate.type.ManyToOneType.disassemble(ManyToOneType.java:98)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:63)
at org.hibernate.loader.Loader.list(Loader.java:1333)
at org.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:106)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1603)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:257)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:373)
at web.pager.CriteriaPager.init(CriteriaPager.java:72)
at web.pager.CriteriaPager.getPageElements(CriteriaPager.java:130)
at web.action.RicercaArticoloAction.go(RicercaArticoloAction.java:170)
at web.action.AbstractAction.execute(AbstractAction.java:190)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:169)
[snip]
The code I execute:
Code:
criteria.setProjection( Projections.rowCount() );
int elementsSize = 0;
try {
elementsSize = Integer.parseInt(criteria.uniqueResult().toString());
} catch( Exception e ) {
e.printStackTrace( System.out );
}
criteria.setProjection( null );
Any idea on this?
I'd like to receive comments on this component. I use it with WebWork, if I get this working I can contribute it, if anyone is interested.
Hibernate version: Hibernate 3 beta 3
Mapping documents:ArticoloCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class
name="web.model.Articolo"
table="ARTICOLO"
>
<cache usage="read-write" />
<id
name="id"
type="java.lang.String"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="catalogo"
type="java.lang.String"
column="CATALOGO"
length="64"
/>
[snip]
<many-to-one
name="genere"
class="web.model.Genere"
not-null="true"
>
<column name="GENEREID" />
</many-to-one>
<many-to-one
name="autore"
class="web.model.Autore"
not-null="true"
>
<column name="AUTOREID" />
</many-to-one>
</class>
</hibernate-mapping>
AutoreCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class
name="web.model.Autore"
table="AUTORE"
>
<cache usage="read-write" />
<id
name="id"
type="long"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="nome"
type="java.lang.String"
column="NOME"
length="256"
/>
<property
name="descrizione"
type="java.lang.String"
column="DESCRIZIONE"
length="1024"
/>
<property
name="posizione"
type="java.lang.String"
column="POSIZIONE"
length="256"
/>
<set
name="articoloList"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="AUTOREID" />
</key>
<one-to-many
class="web.model.Articolo"
/>
</set>
</class>
</hibernate-mapping>
GenereCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class
name="web.model.Genere"
table="GENERE"
>
<cache usage="read-write" />
<id
name="id"
type="long"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="nome"
type="java.lang.String"
column="NOME"
length="64"
/>
<set
name="articoloList"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="GENEREID" />
</key>
<one-to-many
class="web.model.Articolo"
/>
</set>
<many-to-one
name="categoria"
class="web.model.Categoria"
not-null="true"
>
<column name="CATEGORIAID" />
</many-to-one>
</class>
</hibernate-mapping>
Name and version of the database you are using:Oracle DB 9.2.0.5
The generated SQL (show_sql=true):Code:
Hibernate: select count(*) as y0_ from ARTICOLO this_ where lower(this_.ID) like ?
[/b]