3

While integrating spring data JPA with postgres. I have a DB table representing the following java object.

private class A {

@Column(name="createdTime", columnDefiniton="TIMESTAMP WITH TIMEZONE")
OffsetDateTime dateTime;
}

I'm trying to save to this table, however, i am getting

Caused by: org.postgresql.util.PSQLException: ERROR: column "created_time" is of type timestamp with time zone but expression is of type bytea
  Hint: You will need to rewrite or cast the expression.
  Position: 131
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:495) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:441) ~[postgresql-9.4-1206-jdbc42.jar:9.4]
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

I did notice that postgres jdbc jar has 2 versions of AbstractJdbcStatement & AbstractJdbc42Statement. As postgresql-9.4-1206-jdbc42.jar:9.4 supports JDBC 4.2, im assuming calling the wrong class is causing this exception.

Bharath
  • 1,787
  • 1
  • 20
  • 37
  • 1
    Can you add the full exception, as well as the versions of jpa and the underlying impl and its version? Also, take a read of this: http://stackoverflow.com/questions/23718383/jpa-support-for-java-8-new-date-and-time-api – Taylor Oct 26 '16 at 16:51
  • @Taylor: i was heading in the right direction to fix this problem. The problem is, i am using spring boot data jpa started which uses hibernate core version 5.0.11 which does not call the postgres jdbc 4.2 supported classes. – Bharath Oct 26 '16 at 19:19

1 Answers1

4

Spring data jpa starter 1.4.1.RELEASE uses hibernate 5.0.11. overriding hibernate.version property to the latest version fixed the issues.

Bharath
  • 1,787
  • 1
  • 20
  • 37