DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Key: NUCMONGODB-100
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Julian Graham
Votes: 0
Watchers: 0
Operations

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

Support use of Java enum value as query parameter evaluating in datastore

Created: 27/Jul/12 01:50 AM   Updated: 09/Aug/12 03:33 PM   Resolved: 07/Aug/12 10:15 AM
Component/s: Query
Affects Version/s: None
Fix Version/s: 3.1.1

File Attachments: 1. Zip Archive enumparameter.zip (3 kB)


Datastore: MongoDB
Severity: Development


 Description  « Hide
It doesn't seem like there's a way to use a Java enumeration value as a query parameter in a JPQL query against MongoDB. For a query like:

  em.createQuery("SELECT o FROM myObject o WHERE o.enumVal = :0").setParameter(0, MyEnum.VALUE_1).getResultList();

...you get the message:

  Jul 26, 2012 7:48:31 PM org.datanucleus.store.mongodb.query.QueryToMongoDBMapper processParameterExpression
  INFO: Dont currently support parameter values of type org.datanucleus.test.MyEnum

...and an empty result set is returned. If you use the enum's ordinal value as the parameter instead, you get the following:

Parameter "0" was specified as java.lang.Integer but should have been org.datanucleus.test.MyEnum
org.datanucleus.exceptions.NucleusUserException: Parameter "0" was specified as java.lang.Integer but should have been org.datanucleus.test.MyEnum
at org.datanucleus.store.query.Query.checkParameterTypesAgainstCompilation(Query.java:2305)
at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:313)
at org.datanucleus.store.mongodb.query.JPQLQuery.compileInternal(JPQLQuery.java:160)
at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:824)
at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:457)
at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:56)
at org.datanucleus.test.Main.main(Main.java:41)


Julian Graham made changes - 27/Jul/12 01:50 AM
Field Original Value New Value
Attachment enumparameter.zip [ 11693 ]
Andy Jefferson added a comment - 07/Aug/12 09:39 AM
I get no such exception running that query, but I simply get the info message in the log. Consequently this is allowing that query to be evaluated in the datastore.

08:31:47,642 (org.datanucleus.test.Main.main()) INFO [DataNucleus.Query] - Dont currently support parameter values of type org.datanucleus.test.MyEnum
08:31:47,642 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Query] - Compilation of filter to be evaluated completely in-datastore was impossible : Parameter expression is not supported by this mapper
...
08:31:47,650 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Datastore.Retrieve] - Fetching instances of collection my_object fields={ "enum_val" : 1 , "_id" : 1} with filter={ }
...
08:31:47,672 (org.datanucleus.test.Main.main()) DEBUG [DataNucleus.Query] - JPQL Query : Processing the "filter" clause using in-memory evaluation (clause = "DyadicExpression{PrimaryExpression{o.enumVal} = ParameterExpression{0}}")

Andy Jefferson made changes - 07/Aug/12 09:39 AM
Summary Can't use Java enum value as query parameter Support use of Java enum value as query parameter evaluating in datastore
Issue Type Bug [ 1 ] Improvement [ 4 ]
Affects Version/s 3.1.0.release [ 11471 ]
Priority Major [ 3 ] Minor [ 4 ]
Andy Jefferson made changes - 07/Aug/12 10:15 AM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 3.1.1 [ 11634 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 09/Aug/12 03:33 PM
Status Resolved [ 5 ] Closed [ 6 ]