openjpa-dev mailing list archives

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

     [ https://issues.apache.org/jira/browse/OPENJPA-1950?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Vermeulen updated OPENJPA-1950:
-------------------------------

    Attachment: OPENJPA-1950-TestCase.zip

My own TestCase that shows the problem.

> exception when converting datetime2 result from String to java.util.Date (ms sql server)

> -----------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1950
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1950
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: integration, jdbc, third-party
>    Affects Versions: 2.1.0
>            Reporter: Vermeulen
>         Attachments: OPENJPA-1950-TestCase.zip
>
>
> 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:
> @Entity
> public class DateTestEntity {
> ...
> 	@Temporal(TemporalType.DATE)
> 	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(z.date) 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(z.date) FROM DateTestEntity z". 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 DateTest.findMaxDate(DateTest.java:96)
> 	at DateTest.testSelectDate(DateTest.java:41)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:168)
> 	at junit.framework.TestCase.runBare(TestCase.java:134)
> 	at junit.framework.TestResult$1.protect(TestResult.java:110)
> 	at junit.framework.TestResult.runProtected(TestResult.java:128)
> 	at junit.framework.TestResult.run(TestResult.java:113)
> 	at junit.framework.TestCase.run(TestCase.java:124)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:232)
> 	at junit.framework.TestSuite.run(TestSuite.java:227)
> 	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> 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(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)
> 	... 25 more
> What is weird is that the query "SELECT z.date FROM DateTestEntity z" does correctly
convert to java.util.Date.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message