Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unable to retrieve timestampz from postgresql db(Eclipselink gives ConversionException retrieving timestamptz field from postgresql database)
Unable to retrieve timestampz from postgresql db [message #1774480] Mon, 16 October 2017 08:51 Go to next message
Alberto Brosich is currently offline Alberto BrosichFriend
Messages: 2
Registered: October 2017
Junior Member
Hello,
I need to read a timestamptz field of a postgresql (9.6.5) table.

I receive the following error:

[javax.persistence.PersistenceException - Exception [EclipseLink-3005] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.ConversionException
Exception Description: Incorrect timestamp format: [2015-07-10 11:53:00+00] (expected [YYYY-MM-DD HH:MM:SS.NNNNNNNNN])]

The entity column is defined as follow:
@Column(name="time")
@Temporal(TemporalType.TIMESTAMP)
private Calendar time;

I'm able to persist but unable to retrieve. Weird...

I tried other java types (e.g. java.sql.Timestamp) without success.
The application run on openjdk version "1.8.0_144".

Any suggest?
Do I have to write a Converter?
Why the behaviour differ between persisting and finding?
Re: Unable to retrieve timestampz from postgresql db [message #1774588 is a reply to message #1774480] Tue, 17 October 2017 14:56 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1275
Registered: July 2009
Senior Member
Odd - what is the database column type, and what is the exception stack trace?
Re: Unable to retrieve timestampz from postgresql db [message #1775761 is a reply to message #1774480] Sun, 05 November 2017 21:49 Go to previous messageGo to next message
Alberto Brosich is currently offline Alberto BrosichFriend
Messages: 2
Registered: October 2017
Junior Member
Sorry for the late response.

I haven't still found a good solution to deal with postgresql timestamptz fields.
The columns in the database are of type "timestamptz(0)".

The best solution for me would be to use ZonedDateTime fields on java side, but unfortunately it is not supported by JPA 2.2.

I'm using the latest version of Eclipselink (2.7.0), Postgresql JDBC driver (42.1.4), java (1.8.0_151).

I tried Date, Calendar and GregorianCalendar using @Temporal annotation, java.sql.Timestamp and OffsetDateTime,

Is there a best practice for timestamptz?

Regards
Re: Unable to retrieve timestampz from postgresql db [message #1775892 is a reply to message #1775761] Tue, 07 November 2017 17:17 Go to previous message
Rodolfo Fortes is currently offline Rodolfo FortesFriend
Messages: 2
Registered: November 2017
Junior Member
I guess it's because the timezone.
Try to add this to your field:

@Column(columnDefinition= "TIMESTAMP WITH TIME ZONE")
Previous Topic:Logging about time to create entity manager factory Impl should exist
Next Topic:EclipseLink 2.6 Long Primary Key Mapping PostgreSQL
Goto Forum:
  


Current Time: Fri Dec 15 21:31:50 GMT 2017

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

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