Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1.3
Name and version of the database you are using: Firebird 1.5
Can I use FetchMode.JOIN with Criteria.DISTINCT_ROOT_ENTITY and setMaxResult?
I've used FetchMode.JOIN to solve N + 1 select problem and Criteria.DISTINCT_ROOT_ENTITY to remove duplicate entries.
The query runs properly this way but if I add setMaxResult I get a strange exception.
I have a class with 2 lists:
Declaration:
-- List persons
-- List address
Code:
Criteria criteria = session.createCriteria(Declaration.class);
criteria.setFetchMode("persons", FetchMode.JOIN);
criteria.setFetchMode("address", FetchMode.JOIN);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
If I put setMaxResult(10) for example, I get an exception like:
Code:
Exception in thread "main" Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.psleuropa.paco.models.common.handlers.paco.DatosAplicacionHandler.listDeclaracionFilterCriteria(DatosAplicacionHandler.java:430)
at com.psleuropa.paco.models.common.handlers.paco.DatosAplicacionHandler.listDeclaraciones(DatosAplicacionHandler.java:235)
... 2 more
[b]Caused by: org.firebirdsql.jdbc.field.TypeConvertionException: Error converting to int. 1111222233334444555566667777[/b]
at org.firebirdsql.jdbc.field.FBIntegerField.setString(FBIntegerField.java:124)
at org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStatement.java:383)
at org.hibernate.type.StringType.set(StringType.java:26)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 9 more
Java Result: 1