Issue Details (XML | Word | Printable)

Key: NUCJODATIME-6
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Unassigned
Reporter: Dmitry J. Voronov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Types : JodaTime

JodaLocalDateLiteral is trying to cast LocalDate to DateTime

Created: 09/Mar/11 03:23 PM   Updated: 07/Nov/11 02:58 PM   Resolved: 09/Mar/11 03:58 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 3.0.0.m2

Environment:
The affected version of all datanucleus platform is 3.0.0.m2
The Joda Time version is 1.6.2

Datastore: PostgreSQL
Severity: Development


 Description  « Hide
LocalDate and DateTime classes in fact cannot be cross-casted.
I suggest to replace line 71 of JodaLocalDateLiteral.java:
date.setTime(((DateTime)value).getMillis());
to:
date.setTime(value.toDateMidnight().getMillis());

P.S. Priority has been set to blocker,
because LocalDate seems to be completely unusable for now.


java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:596)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:300)
at org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory.newLiteralParameter(SQLExpressionFactory.java:258)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processParameterExpression(QueryToSQLMapper.java:2509)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processParameterExpression(QueryToSQLMapper.java:2363)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compilePrimaryExpression(AbstractExpressionEvaluator.java:180)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileUnaryExpression(AbstractExpressionEvaluator.java:165)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileAdditiveMultiplicativeExpression(AbstractExpressionEvaluator.java:144)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:119)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:65)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:46)
at org.datanucleus.query.expression.Expression.evaluate(Expression.java:333)
at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:70)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:440)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:360)
at org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:873)
at org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:332)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1663)
at org.datanucleus.store.query.Query.executeWithArray(Query.java:1527)
at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:312)
at net.retn.iris.server.q.QueryBuilder.execute(QueryBuilder.java:137)
Caused by: java.lang.ClassCastException: org.joda.time.LocalDate cannot be cast to org.joda.time.DateTime
at org.datanucleus.store.rdbms.sql.expression.JodaLocalDateLiteral.<init>(JodaLocalDateLiteral.java:71)
... 54 more

Sort Order: Ascending order - Click to sort in descending order
Dmitry J. Voronov added a comment - 09/Mar/11 03:33 PM
Oh no, the correct patch should be

date.setTime(((DateTime)value).getMillis());
to:
date.setTime(((LocalDate)value).toDateMidnight().getMillis());

Andy Jefferson added a comment - 09/Mar/11 03:58 PM
In fact this is a cut-and-paste typo from one of the other classes. SVN trunk fixes it and adds a unit test. Thx. In future, please provide a test that demonstrates the problem so then we can add it to the test suite