Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute an UPDATE JPQL Query against a domain class that contains 'Set' in its name #274

Closed
rm3l opened this issue Jan 12, 2018 · 1 comment
Labels
Milestone

Comments

@rm3l
Copy link

rm3l commented Jan 12, 2018

Hi!

I'm trying to run the following simple JPQL Update query, but DataNucleus is unable to parse the query string:

entityManager
        .createQuery("UPDATE Setting s SET s.value = :valueToSet WHERE s.id = :id")
        .setParameter("valueToSet", "my.new.value")
        .setParameter("id", setting.getId())
        .executeUpdate();

Here is the stacktrace:

12:15:06,230 (main) ERROR [DataNucleus.General] - >> Exception in test testUpdateSetting_doesNotWorkWithDN
Method/Identifier expected at character 1 in ""
org.datanucleus.store.query.QueryCompilerSyntaxException: Method/Identifier expected at character 1 in ""
        at org.datanucleus.query.compiler.JPQLParser.processPrimary(JPQLParser.java:1390)
        at org.datanucleus.query.compiler.JPQLParser.processUnaryExpression(JPQLParser.java:1221)
        at org.datanucleus.query.compiler.JPQLParser.processMultiplicativeExpression(JPQLParser.java:1154)
        at org.datanucleus.query.compiler.JPQLParser.processAdditiveExpression(JPQLParser.java:1125)
        at org.datanucleus.query.compiler.JPQLParser.processRelationalExpression(JPQLParser.java:582)
        at org.datanucleus.query.compiler.JPQLParser.processAndExpression(JPQLParser.java:565)
        at org.datanucleus.query.compiler.JPQLParser.processOrExpression(JPQLParser.java:546)
        at org.datanucleus.query.compiler.JPQLParser.processExpression(JPQLParser.java:535)
        at org.datanucleus.query.compiler.JPQLParser.processFromExpression(JPQLParser.java:293)
        at org.datanucleus.query.compiler.JPQLParser.parseFrom(JPQLParser.java:91)
        at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:206)
        at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:84)
        at org.datanucleus.store.query.AbstractJPQLQuery.compileGeneric(AbstractJPQLQuery.java:304)
        at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:365)
        at org.datanucleus.store.rdbms.query.JPQLQuery.compileInternal(JPQLQuery.java:235)
        at org.datanucleus.store.query.Query.setImplicitParameter(Query.java:975)
        at org.datanucleus.store.rdbms.query.JPQLQuery.setImplicitParameter(JPQLQuery.java:169)
        at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:548)
        at org.datanucleus.api.jpa.JPAQuery.setParameter(JPAQuery.java:61)
        at org.datanucleus.test.SimpleTest.lambda$testUpdateSetting_doesNotWorkWithDN$4(SimpleTest.java:112)

Using a different domain class works however:

entityManager
        .createQuery("UPDATE Person p SET p.email = :email WHERE p.id = :id")
        .setParameter("email", "luke@skywalk.er")
        .setParameter("id", person.getId())
        .executeUpdate()

I suspect the issue might be at this line: https://github.com/datanucleus/datanucleus-core/blob/master/src/main/java/org/datanucleus/query/JPQLSingleStringParser.java#L310

Versions:

<dn.core.min.ver>5.0.1</dn.core.min.ver>
<dn.core.max.ver>5.1.99</dn.core.max.ver>
<dn.api_jpa.min.ver>5.0.1</dn.api_jpa.min.ver>
<dn.api_jpa.max.ver>5.1.99</dn.api_jpa.max.ver>
<dn.datastore.min.ver>5.0.1</dn.datastore.min.ver>
<dn.datastore.max.ver>5.1.99</dn.datastore.max.ver>
<dn.maven.plugin.ver>5.0.2</dn.maven.plugin.ver>

Am I missing something?

Test case: https://github.com/rm3l/dn-issue-updating-entity-with-set-in-name

This test case contains a set of Maven profiles that run the same tests against other JPA providers. The tests work as expected with EclipseLink and Hibernate, but not with DataNucleus.
To run the tests against DataNucleus (default profile): mvn clean compile test
To run the tests against EclipseLink: mvn clean compile test -P eclipselink
To run the tests against Hibernate: mvn clean compile test -P hibernate

@andyjefferson andyjefferson added this to the 5.1.6 milestone Jan 12, 2018
@rm3l
Copy link
Author

rm3l commented Jan 12, 2018

Thanks for your reactivity, @andyjefferson !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants