These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Can I use FetchMode.JOIN with DISTINCT and setMaxResult?
PostPosted: Wed Aug 30, 2006 8:38 am 
Newbie

Joined: Wed Aug 30, 2006 3:09 am
Posts: 7
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



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.