Problem with datediff using Datepart.day #460

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

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 20, 2013

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 21, 2013

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 27, 2013

Member

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

Member

timowest commented Jul 27, 2013

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2013

Member

Released in 3.2.2

Member

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