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

Illegal type with string aggregation #489

Closed
Ghalleb opened this Issue Sep 4, 2013 · 10 comments

Comments

Projects
None yet
2 participants
@Ghalleb

Ghalleb commented Sep 4, 2013

After upgrading from QueryDSL 3.2.1 to 3.2.2 (same problem in 3.2.3) I have this stacktrace :

....
Caused by: java.lang.IllegalArgumentException: Illegal type : String
at com.mysema.util.MathUtils.cast(MathUtils.java:71) [querydsl-core-3.2.3.jar:]
at com.mysema.query.support.NumberConversions.newInstance(NumberConversions.java:61) [querydsl-core-3.2.3.jar:]
at com.mysema.query.jpa.FactoryExpressionTransformer.transformTuple(FactoryExpressionTransformer.java:50) [querydsl-jpa-3.2.3.jar:]
at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:95) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:431) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2338) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.loader.Loader.list(Loader.java:2333) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1827) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157) [hibernate-core-4.2.2.Final.jar:4.2.2.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264) [hibernate-entitymanager-4.2.2.Final.jar:4.2.2.Final]
at com.mysema.query.jpa.sql.AbstractJPASQLQuery.getResultList(AbstractJPASQLQuery.java:193) [querydsl-jpa-3.2.3.jar:]
at com.mysema.query.jpa.sql.AbstractJPASQLQuery.list(AbstractJPASQLQuery.java:224) [querydsl-jpa-3.2.3.jar:]
at com.mycompany.core.reporting.ReportingServiceImpl.execute(ReportingServiceImpl.java:895) [scm-ejb.jar:]

My code:

final List<Object[]> resultS = queryS.list(Projections.array(Object[].class, selectedNumberPaths.values().toArray(new SimpleExpression[selectedNumberPaths.size()])));

It seems to be a problem with the projection as there was not need to use projection in 3.2.1

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 4, 2013

Member

I also need the contents of selectedNumberPaths. It looks like a cast from Number to String fails. Number in the result data and String on the Querydsl expression level.

Member

timowest commented Sep 4, 2013

I also need the contents of selectedNumberPaths. It looks like a cast from Number to String fails. Number in the result data and String on the Querydsl expression level.

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Sep 4, 2013

I'll try to send you a simple test case later.
I cannot paste my code here, it's really too complex...

Ghalleb commented Sep 4, 2013

I'll try to send you a simple test case later.
I cannot paste my code here, it's really too complex...

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Sep 4, 2013

Here is a sample test case:

    final PathBuilder<Object[]> subAlias = new PathBuilder<Object[]>(Object[].class, "sub");

    ...

    selectedNumberPaths = new LinkedHashMap<ReportField, SimpleExpression<?>>();

    selectedNumberPaths.put(ReportField.totaldeaths, ((SimpleExpression) subAlias.getNumber("totaldeaths", BigDecimal.class).sum()).as("totaldeaths"));
    selectedNumberPaths.put(ReportField.month, ((SimpleExpression) subAlias.getString("month")).as("month"));

    final List<Object[]> resultS = queryS.list(Projections.array(Object[].class,
            selectedNumberPaths.values().toArray(new SimpleExpression[selectedNumberPaths.size()])));

It strange, i really have to put the 2 objects in selectedNumberPaths otherwise it works....

Ghalleb commented Sep 4, 2013

Here is a sample test case:

    final PathBuilder<Object[]> subAlias = new PathBuilder<Object[]>(Object[].class, "sub");

    ...

    selectedNumberPaths = new LinkedHashMap<ReportField, SimpleExpression<?>>();

    selectedNumberPaths.put(ReportField.totaldeaths, ((SimpleExpression) subAlias.getNumber("totaldeaths", BigDecimal.class).sum()).as("totaldeaths"));
    selectedNumberPaths.put(ReportField.month, ((SimpleExpression) subAlias.getString("month")).as("month"));

    final List<Object[]> resultS = queryS.list(Projections.array(Object[].class,
            selectedNumberPaths.values().toArray(new SimpleExpression[selectedNumberPaths.size()])));

It strange, i really have to put the 2 objects in selectedNumberPaths otherwise it works....

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 4, 2013

Member

What about this one?

selectedNumberPaths.put(ReportField.month, ((SimpleExpression) subAlias.getString("month")).as("month"));

Is this also a String on the database level?

Member

timowest commented Sep 4, 2013

What about this one?

selectedNumberPaths.put(ReportField.month, ((SimpleExpression) subAlias.getString("month")).as("month"));

Is this also a String on the database level?

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Sep 5, 2013

In fact, in the subAlias, month is extracted from a dateTime:

queryFieldsCommon.add(SLog.log.logtime.yearMonth().as("month"));

But in the end, it's a String (I hope so ;-))

Ghalleb commented Sep 5, 2013

In fact, in the subAlias, month is extracted from a dateTime:

queryFieldsCommon.add(SLog.log.logtime.yearMonth().as("month"));

But in the end, it's a String (I hope so ;-))

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 5, 2013

Member

I can change the Exception, but there won't be a coercion to String. You are responsible for creating subpaths via PathBuilder that correspond to the real types in the result set.

Member

timowest commented Sep 5, 2013

I can change the Exception, but there won't be a coercion to String. You are responsible for creating subpaths via PathBuilder that correspond to the real types in the result set.

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Sep 5, 2013

In fact, it was OK in 3.2.1, I didn't change anything at all.

I'll try to see if using a "pure" string give me the same error

Ghalleb commented Sep 5, 2013

In fact, it was OK in 3.2.1, I didn't change anything at all.

I'll try to see if using a "pure" string give me the same error

@Ghalleb

This comment has been minimized.

Show comment
Hide comment
@Ghalleb

Ghalleb Sep 5, 2013

With a "pure" string, everything is ok.

So I changed

queryFieldsCommon.add(SLog.log.logtime.yearMonth().as("month"));

to

queryFieldsCommon.add(SLog.log.logtime.yearMonth().stringValue().as("month"));

and now everything works like a charm....

Thanks for the help

Ghalleb commented Sep 5, 2013

With a "pure" string, everything is ok.

So I changed

queryFieldsCommon.add(SLog.log.logtime.yearMonth().as("month"));

to

queryFieldsCommon.add(SLog.log.logtime.yearMonth().stringValue().as("month"));

and now everything works like a charm....

Thanks for the help

timowest added a commit that referenced this issue Sep 5, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 5, 2013

Member

I made the conversion now safer, but still users should use the correct types.

Member

timowest commented Sep 5, 2013

I made the conversion now safer, but still users should use the correct types.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 20, 2013

Member

Released in 3.2.4

Member

timowest commented Oct 20, 2013

Released in 3.2.4

@timowest timowest closed this Oct 20, 2013

@timowest timowest added this to the 3.2.4 milestone Apr 13, 2014

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