openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vermeulen (JIRA)" <>
Subject [jira] Created: (OPENJPA-1950) exception when converting datetime2 result from String to java.util.Date (ms sql server)
Date Tue, 22 Feb 2011 13:17:38 GMT
exception when converting datetime2 result from String to java.util.Date (ms sql server) 

                 Key: OPENJPA-1950
             Project: OpenJPA
          Issue Type: Bug
          Components: integration, jdbc, third-party
    Affects Versions: 2.1.0
            Reporter: Vermeulen

OPENJPA-1759 (included in OpenJPA 2.1.0) added support for datetime2 in sql server. Schema
generation uses this type instead of datetime which was generated with earlier versions.
When I have an entity with a java.util.Date column like:

public class DateTestEntity {
	private Date date;

Performing the following query with expected result type java.util.Date fails (also happens
with OpenJpa 2.0.0 when there is an existing table column of type datetime2).

    "SELECT max( FROM DateTestEntity z" 

This throws the following exception:

<openjpa-2.1.0-r422266:1071316 nonfatal user error> org.apache.openjpa.persistence.ArgumentException:
Failed to execute query "SELECT max( FROM DateTestEntity z". Check the query syntax
for correctness. See nested exception for details.
	at org.apache.openjpa.kernel.QueryImpl.execute(
	at org.apache.openjpa.kernel.QueryImpl.execute(
	at org.apache.openjpa.kernel.DelegatingQuery.execute(
	at org.apache.openjpa.persistence.QueryImpl.execute(
	at org.apache.openjpa.persistence.QueryImpl.getResultList(
	at DateTest.findMaxDate(
	at DateTest.testSelectDate(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at junit.framework.TestCase.runTest(
	at junit.framework.TestCase.runBare(
	at junit.framework.TestResult$1.protect(
	at junit.framework.TestResult.runProtected(
	at junit.framework.TestSuite.runTest(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: java.lang.ClassCastException: Cannot convert object "2011-02-22 00:00:00.0000000"
of type "class java.lang.String" into an instance of "class java.util.Date".
	at org.apache.openjpa.kernel.Filters.convert(
	at org.apache.openjpa.kernel.Filters.convert(
	at org.apache.openjpa.jdbc.kernel.exps.UnaryOp.load(
	at org.apache.openjpa.jdbc.kernel.ProjectionResultObjectProvider.getResultObject(
	at org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.getResultObject(
	at org.apache.openjpa.kernel.QueryImpl.singleResult(
	at org.apache.openjpa.kernel.QueryImpl.toResult(
	at org.apache.openjpa.kernel.QueryImpl.execute(
	at org.apache.openjpa.kernel.QueryImpl.execute(
	... 25 more

What is weird is that the query "SELECT FROM DateTestEntity z" does correctly convert
to java.util.Date.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message