LocalDateTime setting in jooq.update operation

19 views
Skip to first unread message

YANA

unread,
Feb 19, 2024, 10:55:28 AMFeb 19
to jOOQ User Group
Hi!
I will very grateful for your consultation. Faced exception, tied with TemporalAccessor.
I see, that my TRANSACTIONS table generated using LocalDateTime type field for transaction_date column.
During writing the tests I wanted to set transaction_date for several transactions I interested in. But there always throw exception.
Details below:
Generated  table field:
----------------------------------------------------------------
public final TableField<Record, LocalDateTime> TRANSACTION_DATE = createField(DSL.name("TRANSACTION_DATE"), SQLDataType.LOCALDATETIME(6), this, "");
----------------------------------------------------------
QUERY I want to use in tests:
----------------------------------------------------------
jooq.update(TRANSACTIONS)
.set(TRANSACTIONS.TRANSACTION_DATE, LocalDateTime.from(Instant.now()))
.where(TRANSACTIONS.ID.in(uuid("fe44ac34-df26-d847-d013-6cc71b1e8193")).execute();

---------------------------------------------------------------
Exception:
---------------------------------------------------------------
java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: 2024-02-18T15:20:55.286412600Z of type java.time.Instant
Thanks in advance!

Lukas Eder

unread,
Feb 20, 2024, 2:56:23 AMFeb 20
to jooq...@googlegroups.com
Thanks for your message.

Try this in isolation: LocalDateTime.from(Instant.now()). It produces:

Exception in thread "main" java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: 2024-02-20T07:53:51.119531500Z of type java.time.Instant
at java.base/java.time.LocalDateTime.from(LocalDateTime.java:463)
at org.jooq.testscripts.JDBC.main(JDBC.java:40)
Caused by: java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: 2024-02-20T07:53:51.119531500Z of type java.time.Instant
at java.base/java.time.LocalDate.from(LocalDate.java:403)
at java.base/java.time.LocalDateTime.from(LocalDateTime.java:458)
... 1 more

As you can see, this isn't related to jOOQ. You can see this from the stack trace as well, the problem happens within LocalDateTime.from() and the thing you're passing to LocalDateTime.from() is also in your code.

Why not just call LocalDateTime.now()

I hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/b319e710-ffcc-4bf4-879d-2c924169589bn%40googlegroups.com.

YANA

unread,
Feb 20, 2024, 3:29:09 AMFeb 20
to jOOQ User Group
LocalDateTime.now()  really works.
Thanks a lot for answer. The problem is only in my experience and may be in attentiveness absence at the end of day. So excuse me I took you time. Have a nice day!
вторник, 20 февраля 2024 г. в 08:56:23 UTC+1, lukas...@gmail.com:

Lukas Eder

unread,
Feb 21, 2024, 2:26:20 AMFeb 21
to jooq...@googlegroups.com
No worries :)
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/fef5c69d-762b-472b-97ca-b331c214d0a0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages