New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when using nested MappingProjection with single Expression #295

Closed
Kwaq opened this Issue Nov 28, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@Kwaq

Kwaq commented Nov 28, 2012

Version: 2.9.0

I'm getting this exception:

java.lang.ClassCastException: java.lang.String cannot be cast to com.example.ResultPart
    at com.example.MappingTest$2.map(MappingTest.java:58)
    at com.example.MappingTest$2.map(MappingTest.java:1)
    at com.mysema.query.types.MappingProjection.newInstance(MappingProjection.java:69)
    at com.mysema.query.types.FactoryExpressionUtils$FactoryExpressionAdapter.newInstance(FactoryExpressionUtils.java:51)
    at com.mysema.query.jpa.hibernate.FactoryExpressionTransformer.transformTuple(FactoryExpressionTransformer.java:46)
    at org.hibernate.hql.HolderInstantiator.instantiate(HolderInstantiator.java:96)
    at org.hibernate.loader.hql.QueryLoader.getResultList(QueryLoader.java:423)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getResultList(AbstractJPAQuery.java:221)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:273)

Executing following code

        final JPAQuery query = new JPAQuery(entityManager);

        final QSomeEntity ent = QSomeEntity.someEntity;
        final MappingProjection<ResultPart> key = new MappingProjection<ResultPart>(ResultPart.class,
            ent.firstProperty) {

            @Override
            protected ResultPart map(final Tuple row) {
                return new ResultPart();
            }

        };
        final List<ResultObject> list = query.from(ent).list(
            new MappingProjection<ResultObject>(ResultObject.class, key) {

                @Override
                protected ResultObject map(final Tuple row) {
                    final ResultPart consolidationKey = row.get(key);
                    return new ResultObject();
                }
            });

Changing key projection declaration to

        final MappingProjection<ResultPart> key = new MappingProjection<ResultPart>(ResultPart.class,
            ent.firstProperty, ent.secondProperty) {

            @Override
            protected ResultPart map(final Tuple row) {
                return new ResultPart();
            }

        };

As You notice, the only difference is that in second case I pass two expressions to MappingProjection constructor.
I don't fill result objects because it is irrelevant. ResultPart is supposed to be part of the ResultObject.

timowest added a commit that referenced this issue Nov 28, 2012

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jan 13, 2013

Member

Released in 3.0.0.BETA1

Member

timowest commented Jan 13, 2013

Released in 3.0.0.BETA1

@timowest timowest closed this Jan 13, 2013

timowest added a commit that referenced this issue Apr 19, 2013

@timowest timowest added this to the 3.0.0 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment