Skip to content
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

Problem with datediff using Datepart.day #460

Closed
Ghalleb opened this issue Jul 20, 2013 · 4 comments
Closed

Problem with datediff using Datepart.day #460

Ghalleb opened this issue Jul 20, 2013 · 4 comments
Milestone

Comments

@Ghalleb
Copy link

@Ghalleb Ghalleb commented Jul 20, 2013

SQLExpressions.datediff(DatePart.year, Mytable.mytable.statementdate,
            Mytable.mytable.statementdate2).longValue()

produce

cast(date_part('year', age(mytable.statementdate, 
             mytable.statementdate2)) as bigint)

but

SQLExpressions.datediff(DatePart.day, Mytable.mytable.statementdate,
            Mytable.mytable.statementdate2).longValue()

produce

cast((mytable.statementdate::date - mytable.statementdate2::date) as bigint)

And It results in a java error:

javax.ejb.EJBTransactionRolledbackException: org.hibernate.QueryException: Not all named parameters have been set

In fact it seems that only Datepart.year and Datepart.month are working

@timowest
Copy link
Member

@timowest timowest commented Jul 20, 2013

You are using PostgreSQL and JPA native queries in this case? This looks like an Hibernate parser issue, as the column::date might be treated as name parameters instead.

The patterns for the various date diff cases are in PostgresTemplates.

@timowest
Copy link
Member

@timowest timowest commented Jul 21, 2013

It appears that if I replace the expression::type usage with cast(expression as type) it will probably also work in JPA

http://www.postgresql.org/docs/current/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS

@timowest
Copy link
Member

@timowest timowest commented Jul 27, 2013

Could you verify with the latest SNAPSHOT that the fix works for you?

@timowest
Copy link
Member

@timowest timowest commented Jul 29, 2013

Released in 3.2.2

@timowest timowest closed this Jul 29, 2013
@timowest timowest added this to the 3.2.2 milestone Apr 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants