Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-1985

ClassCastException in max(Timestamp) function on PostgreSQL

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.1.0
    • 2.1.1, 2.2.0
    • jdbc, kernel
    • None
    • Windows 7 x64, Java 1.6.0_25, PostgreSQL 9.0.4 x64, PostgreSQL Native Driver PostgreSQL 9.0 JDBC4 (build 801)

    Description

      Works perfectly in OpenJPA 2.0.1.

      Regression in OpenJPA 2.1.0, 100% reproducible exception.

      Exception:
      SEVERE: Failed to execute query "select max(h.loadTimestamp) from Header h where h.code=?1 and h.period=?2". Check the query syntax for correctness. See nested exception for details.
      <openjpa-2.1.0-r422266:1071316 nonfatal user error>
      org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(h.loadTimestamp) from Header h where h.code=?1 and h.period=?2". Check the query syntax for correctness. See nested
      exception for details.
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:305)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:319)
      at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:343)
      ... my code ...
      Caused by: java.lang.ClassCastException: Cannot convert object
      "2011-04-25 15:48:31+02" of type "class org.postgresql.util.PGobject"
      into an instance of "class java.sql.Timestamp".
      at org.apache.openjpa.kernel.Filters.convert(Filters.java:336)
      at org.apache.openjpa.kernel.Filters.convert(Filters.java:265)
      at org.apache.openjpa.jdbc.kernel.exps.UnaryOp.load(UnaryOp.java:125)
      at org.apache.openjpa.jdbc.kernel.ProjectionResultObjectProvider.getResultObject(ProjectionResultObjectProvider.java:78)
      at org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.getResultObject(QueryImpl.java:2075)
      at org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1330)
      at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1242)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      ... 12 more

      Entity:
      @Entity
      @Table(name = "headers")
      @DataCache(enabled = false)
      public class Header {
      @Id
      @GeneratedValue
      private long id;

      @Column(nullable = false)
      private String code;

      @Column(nullable = false)
      private int period;

      @Column(nullable = false)
      @Temporal(TemporalType.TIMESTAMP)
      private Timestamp loadTimestamp;
      ...
      }

      Table (autogenerated by OpenJPA 2.0.1):
      create table public.headers (
      id int8 not null,
      loadtimestamp abstime not null,
      period int4 not null,
      code varchar(255) not null,
      primary key (id)
      );

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mikedd Michael Dick
            s.mironov Stanislav Mironov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment