Regression - yearMonth composite operations break grouping? #474

Closed
magnuskvalheim opened this Issue Aug 15, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@magnuskvalheim

The composite operations now uses variables (prepared statement) which seems to break grouping.

Created off group conversations - https://groups.google.com/forum/#!topic/querydsl/8_p-vr5Yb8o

On Wednesday, August 14, 2013 1:26:38 PM UTC+3, Bård Magnus Kvalheim wrote:
Okay, so was able to bring back the old query by creating a custom numberexpression.

NumberExpression yearMonth = NumberTemplate.create(Integer.class, "year({0}) * 100 + month({0})", QBlog.blog.publishDate);

Now the query runs fine.

A bit of hack, but will work fine for now. I wonder how to do it the "right" way though...

Please let me know if something comes to mind

--magnus

On Wednesday, August 14, 2013 10:49:16 AM UTC+2, Bård Magnus Kvalheim wrote:
Hi.

So we've just upgraded from 2.9.0 to 3.2.2 and corrected the compile issues caused by refactorings.

In running system we've found something that look like regression issues caused by the upgrade.

In query we did grouping of yearMonth which worked in 2.9.0 but fails in 3.2.2

org.postgresql.util.PSQLException
ERROR: column "blog0_.publishdate" must appear in the GROUP BY clause or be used in an aggregate function Position: 26

The query : we are getting a count of blogs grouped by yearmonth in order to create an archive list.

old generated jpql

select blog
from Blog blog
where lower(blog.language) in (?1) and blog.category = ?2 and blog.publishDate < ?3
group by year(blog.publishDate) * 100 + month(blog.publishDate)
order by year(blog.publishDate) * 100 + month(blog.publishDate) desc

new generated jpql

select blog
from Blog blog
where lower(blog.language) in (?1) and blog.category = ?2 and blog.publishDate < ?3
group by year(blog.publishDate) * ?4 + month(blog.publishDate)
order by year(blog.publishDate) * ?4 + month(blog.publishDate) desc

(Apparently don't like the parameter in expression - ?4 )

I can see the related changes in #434 - c640a82

Touchpoints/questions:

  • Is there a way to have querydsl generate same query in 3.2.2 as in 2.9.0 ?
  • Do you know of an alternate/ recommended way of doing the suggested?
  • We are using hibernate as provider with postgresql. Could there be a way to have hibernate use date_trunc through querydsl?

Thanks in advance

best
Magnus

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 15, 2013

Member
  • Is there a way to have querydsl generate same query in 3.2.2 as in 2.9.0 ?

Yes, the behaviour has been reverted now.

  • We are using hibernate as provider with postgresql. Could there be a way to have hibernate use date_trunc through querydsl?

I don't think date_trunc is JPQL, so there is no offical way. You can use it though trough a TemplateExpression.

Member

timowest commented Aug 15, 2013

  • Is there a way to have querydsl generate same query in 3.2.2 as in 2.9.0 ?

Yes, the behaviour has been reverted now.

  • We are using hibernate as provider with postgresql. Could there be a way to have hibernate use date_trunc through querydsl?

I don't think date_trunc is JPQL, so there is no offical way. You can use it though trough a TemplateExpression.

@magnuskvalheim

This comment has been minimized.

Show comment
Hide comment
@magnuskvalheim

magnuskvalheim Aug 16, 2013

That's great. Sorry, about having to revert though.

As always - your impeccable continuous support for querydsl is fantastic.

Thanks
Magnus

That's great. Sorry, about having to revert though.

As always - your impeccable continuous support for querydsl is fantastic.

Thanks
Magnus

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 27, 2013

Member

Released in 3.2.3

Member

timowest commented Aug 27, 2013

Released in 3.2.3

@timowest timowest closed this Aug 27, 2013

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

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