Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Wrong detected type for MIN operator - I think?(EclipseLink db<>Java type mapping)
Wrong detected type for MIN operator - I think? [message #1852478] Tue, 17 May 2022 21:08 Go to next message
Morten Torp Meiling is currently offline Morten Torp MeilingFriend
Messages: 3
Registered: May 2022
Junior Member
I am experiencing a problem with the mapping of database types to java types.

I have an JPQL expression with a MIN(DATE) expression - where the DATE is a java type Instant (as are all dates in my application). I then have an attribute converter for Instant<>LocalDataTime and this works for all other dates than the one inside the MIN expression.
What I can see happen is that for all "normal" occurences of dates in the JPQL, Eclipselink correctly identifies their Java return type to LocalDateTime, and then this gets further converted to Instant in my converter.
But for the data inside the MIN expression, Eclipselink identifies "Instant" as the java return type, and due to the logic in DataBaseAccessor#getObjectThroughOptimizedDataConversion the value from the query ends up being a TimeStamp (instead of a LocalDateTime) which then fails with a class cast exception in my AttributeConverter because it expects LocalDateTimes.

This is a bit of a hard problem to explain - I hope the above made sense, and that someone can help me - or at least point me in some meaningful direction!

Re: Wrong detected type for MIN operator - I think? [message #1854240 is a reply to message #1852478] Mon, 08 August 2022 18:00 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 43
Registered: December 2021
First, is there any reason you are using/expecting a LocalDateTime instance instead of just using java.sql.Timestamp from the driver?

Do you have the flow down when you use DATE is returned and passed to your converter - specifically how it gives your AttributeConverter a LocalDateTime instance instead of a TimeStamp? I suspect it is just getting a Timestamp and going through the conversion manager to call "((java.sql.Timestamp) sourceObject).toLocalDateTime().toLocalDate();" on it to get the LocalDateTime from it for your converter; if so, you might be better off just using a converter directly from Timestamp <->instance, but I don't remember specifics behind time usage.

What version of EclipseLink are you using?

Best Regards,

Previous Topic:migrating from openjpa to eclipselink
Next Topic:Cascade Issue
Goto Forum:

Current Time: Fri Dec 01 23:56:09 GMT 2023

Powered by FUDForum. Page generated in 0.02044 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top