Issue Details (XML | Word | Printable)

Key: NUCRDBMS-815
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Florian Schmitt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

NullPointerException when setting multiple Date parameters

Created: 28/Jul/14 05:50 PM   Updated: 10/Aug/14 12:57 PM   Resolved: 30/Jul/14 03:02 PM
Component/s: None
Affects Version/s: 4.0.1
Fix Version/s: 4.0.2

Environment: Windows 7 64bit, Java 1.8.0_05

Datastore: MySQL
Severity: Production


 Description  « Hide
Im getting a NullPointerException when setting multiple Date parameters on an JPA single string query.

(why cant I attach files here?) [additionally the link 'this guide' below this box is not working...]

Here is a test entity:

@Entity
@Table(name = "test_date")
@TableGenerator(name = "test_date_id", allocationSize = 1)
@Getter
@Setter
public class TestDate implements Serializable
{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "test_date_id")
@Basic(optional = false)
@Column(name = "id", nullable = false)
private Long id;

@Index
@Basic(optional = false)
@Column(name = "date", nullable = false)
@Temporal(TemporalType.DATE)
private Date date;

@Index
@Basic(optional = false)
@Column(name = "date2", nullable = false)
@Temporal(TemporalType.DATE)
private Date date2;

        equals/toString...
}


The following query works:

entityManager.createQuery("Select x From TestDate x Where x.date = :date", TestDate.class)//
.setParameter("date", dateValue) //
.getResultList(); //



This query does not work anymore:

entityManager.createQuery("Select x From TestDate x Where x.date = :date And x.date2 = :date2", TestDate.class)//
.setParameter("date", dateValue) //
.setParameter("date2", dateValue) //
.getResultList(); //



This is the stacktrace:

Caused by: java.lang.NullPointerException
at org.datanucleus.store.rdbms.sql.expression.TemporalLiteral.toString(TemporalLiteral.java:141)
at java.lang.String.valueOf(String.java:2979)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at org.datanucleus.store.rdbms.sql.expression.ExpressionUtils.checkAndCorrectLiteralForConsistentMappingsForBooleanComparison(ExpressionUtils.java:633)
at org.datanucleus.store.rdbms.sql.expression.ExpressionUtils.checkAndCorrectExpressionMappingsForBooleanComparison(ExpressionUtils.java:567)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processEqExpression(QueryToSQLMapper.java:1679)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:78)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:66)
at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:46)
at org.datanucleus.query.expression.Expression.evaluate(Expression.java:332)
at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:75)
at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:72)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:465)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:385)
at org.datanucleus.store.rdbms.query.JPQLQuery.compileQueryFull(JPQLQuery.java:846)
at org.datanucleus.store.rdbms.query.JPQLQuery.compileInternal(JPQLQuery.java:308)
at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:861)
at org.datanucleus.store.rdbms.query.JPQLQuery.setImplicitParameter(JPQLQuery.java:165)
at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:506)


This actually happens at the time the first parameter is set, so thats why the second parameter is still null...

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 28/Jul/14 07:01 PM
"this guide" link fixed thx, but then it is quoted in all docs, forum, JIRA front page etc.

Why you can't attach files only you can answer. I can. Others can.

Florian Schmitt added a comment - 29/Jul/14 12:10 PM
Ok, I got it now, thanks! It seems you can't attach file at the time, when you report a bug, but only afterwards... I didn't know that.

Here is the test case:
https://github.com/florianschmitt/test-jpa

Andy Jefferson added a comment - 30/Jul/14 03:02 PM
GitHub master simply changes the toString to check for null value.