You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Stanislav Mironov <sm...@gmail.com> on 2011/04/25 15:24:06 UTC

OpenJPA 2.1.0 regression: PostgreSQL ClassCastException?

Hi everyone!

After OpenJPA 2.0.1 -> 2.1.0 upgrade I've got this on PostgreSQL 9.0.4
(x64) with PostgreSQL JDBC driver 9.0-801 (latest stable versions):

250  pf  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL 9.0.4
,PostgreSQL Native Driver PostgreSQL 9.0 JDBC4 (build 801)).
455  pf  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.1.0
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 ...
	at java.lang.Thread.run(Thread.java:662)
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

Here is the 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;
...
}

Configuration:
    <persistence-unit name="pf" transaction-type="RESOURCE_LOCAL">
        <!--<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>-->

        <class>pkg.Header</class>

        <properties>
            <property name="openjpa.Multithreaded" value="true"/>
            <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
            <property name="openjpa.BrokerImpl"
value="EvictFromDataCache=true"/>
            <property name="openjpa.DataCache"
value="true(CacheSize=10000, SoftReferenceSize=100000)"/>

            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
            <property name="openjpa.jdbc.MappingDefaults"
                      value="ForeignKeyDeleteAction=restrict,
JoinForeignKeyDeleteAction=restrict"/>
            <!--<property name="openjpa.FetchBatchSize" value="1000"/>-->
            <!--<property name="openjpa.Log"
value="DefaultLevel=INFO,SQL=TRACE"/>-->
        </properties>
    </persistence-unit>

Database schema built automatically with OpenJPA 2.0.1.

Works perfectly in OpenJPA 2.0.1. Regression?

-- 
Stanislav Mironov

Re: OpenJPA 2.1.0 regression: PostgreSQL ClassCastException?

Posted by Michael Dick <mi...@gmail.com>.
The root cause here is that the table was generated with OpenJPA 2.0.1,
which used ABSTIME instead of TIMESTAMP as the column type. The default type
was changed in OPENJPA-1726, and the code that uses the default TS type was
not properly updated. I've updated OPENJPA-1985 with the same info.

A quick workaround is to add this property to persistence.xml

        <property name="openjpa.jdbc.DBDictionary"
value="postgres(timestampTypeName=ABSTIME)"/>

Thanks for reporting the problem and opening a JIRA.

-mike

On Mon, Apr 25, 2011 at 8:24 AM, Stanislav Mironov <sm...@gmail.com>wrote:

> Hi everyone!
>
> After OpenJPA 2.0.1 -> 2.1.0 upgrade I've got this on PostgreSQL 9.0.4
> (x64) with PostgreSQL JDBC driver 9.0-801 (latest stable versions):
>
> 250  pf  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
> "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL 9.0.4
> ,PostgreSQL Native Driver PostgreSQL 9.0 JDBC4 (build 801)).
> 455  pf  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.1.0
> 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 ...
>        at java.lang.Thread.run(Thread.java:662)
> 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
>
> Here is the 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;
> ...
> }
>
> Configuration:
>    <persistence-unit name="pf" transaction-type="RESOURCE_LOCAL">
>
>  <!--<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>-->
>
>        <class>pkg.Header</class>
>
>        <properties>
>            <property name="openjpa.Multithreaded" value="true"/>
>            <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
>            <property name="openjpa.BrokerImpl"
> value="EvictFromDataCache=true"/>
>            <property name="openjpa.DataCache"
> value="true(CacheSize=10000, SoftReferenceSize=100000)"/>
>
>            <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema"/>
>            <property name="openjpa.jdbc.MappingDefaults"
>                      value="ForeignKeyDeleteAction=restrict,
> JoinForeignKeyDeleteAction=restrict"/>
>            <!--<property name="openjpa.FetchBatchSize" value="1000"/>-->
>            <!--<property name="openjpa.Log"
> value="DefaultLevel=INFO,SQL=TRACE"/>-->
>        </properties>
>    </persistence-unit>
>
> Database schema built automatically with OpenJPA 2.0.1.
>
> Works perfectly in OpenJPA 2.0.1. Regression?
>
> --
> Stanislav Mironov
>