Hi,
The syntax looks nice.
I suppose it's future-proof enough, though I can imagine us getting in
trouble if JDBC starts allowing parameterized or custom formats, which may
start with a digit or even (in edge cases) look like a date. That seems
unlikely, so I think it's an acceptable risk.
I'm not entirely sure allowing JDBC literals to be "passed-through" the HQL
will always be intuitive, even if it's already allowed for integers: under
some circumstances we map date-only or time-only types to timestamps, for
example. The database might cast a date-only value to a timestamp
automatically by setting hours/minutes/etc to zero, but I'm not sure that's
what *we* do when persisting, considering the various hacks we have around
timezones; '2019-01-01' might very well be converted to
'2018-12-31T23:00:00', for all I know. As a result, there might be a broad
range of Java types where these literals will be seen as "buggy".
The solution would be to support litterals for the *java* types and
converting them to the correct SQL type automatically depending on the
context, but that will be a hassle, if even possible at all.
I might be wrong, but only exhaustive testing of all literals with all
date/time types on all RDBMS will let us know for sure. Let's keep in mind
how many bugs have surfaced from time-related features in the past...
Yoann Rodière
Hibernate Team
yoann(a)hibernate.org
On Mon, 6 Jan 2020 at 15:57, Steve Ebersole <steve(a)hibernate.org> wrote:
Initially when I started working on 6.0 I added support for defining
temporal literals using JDBC's "escape syntax". JDBC already defines a
syntax for declaring temporal literals using this syntax -
- {d '2020-01-01'} for a Date
- {t '10:10:10'} for a Time
- {ts '2020-01-01 10:10:10'} for a Timestamp
I had planned on using this syntax to define generalized support for adding
new types of literals using the "prefix" which is the first identifier
after the open brace. I did not have any concrete plans for specific types
of literals, although I was hoping this would fit with hibernate-spatial
needs.
Since temporal values are so common I added another simplified form:
- {2020-01-01} for a "Date"
- {10:10:10} for a "Time"
- {2020-01-01 10:10:10} for a "Timestamp"
Notice first the absence of quotes for these. The patterns is defined as a
syntactic element of the grammar (thanks to Gavin King for this particular
idea)[1].
As a side note, I first tried to use back-ticks for these simplified
temporal literals rather than braces but that conflicts with the
`QUOTED_IDENTIFIER` lexer rule. `QUOTED_IDENTIFIER` is never used (and
really kind of meaningless in the HQL grammar) so one option would be to
remove that rule and use the back-ticks for these literals like
`2020-01-01` as opposed to {2020-01-01} if folks like that better.
It's also important to note that I actually use the Java 8 temporal types
internally to represent these simplified literals because it is easy to
translate from one type to another starting from these types.
Anyone have objections or suggestions regarding any of this?
[1] -
https://github.com/hibernate/hibernate-orm/blob/eab6107ec2e7b3a0c06146a9f...
_______________________________________________
hibernate-dev mailing list
hibernate-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev