java.lang.IllegalArgumentException: Invalid reference 'make'!

Spring JIRA | Adil Fulara | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Mongo Shell working command. {code} db.person.aggregate( { $unwind: "$descriptors.carDescriptor.entries" }, {$project: {make: "$descriptors.carDescriptor.entries.make", model: "$descriptors.carDescriptor.entries.model", firstName:"$firstName", lastName: "$lastName"}}, {$group: {_id: "$make"}} ) {code} Equivalent Spring Data representation {code} Aggregation agg = Aggregation.newAggregation( unwind("descriptors.carDescriptor.entries"), project() .and("descriptors.carDescriptor.entries.make").as("make") .and("descriptors.carDescriptor.entries.model").as("model") .and("firstName").as("firstName") .and("lastName").as("lastName"), group("make") ); {code} While the Mongo Shell query work fine, Spring MongoTemplate form does not and returns the following error {noformat} java.lang.IllegalArgumentException: Invalid reference 'make'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:92) at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62) at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:292) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1323) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1306) at com.example.samples.MongoTemplateTest.testAggregation(MongoTemplateTest.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {noformat} Pojo classes {code} // getter, setter omitted @Document public class Person { @Id private String id; private String firstName; private String lastName; private Descriptors descriptors; } public class Descriptors { private CarDescriptor carDescriptor; } public class CarDescriptor { private List<Entry> entries; class Entry { private String make; private String model; private int year; } } {code} To confirm if "make" is being returned remove the group("make") operator from the fluent api and the output shows that the make is indeed being returned. Any pointers / work arounds ? Thank you, Adil Fulara

    Spring JIRA | 3 years ago | Adil Fulara
    java.lang.IllegalArgumentException: Invalid reference 'make'!
  2. 0

    Mongo Shell working command. {code} db.person.aggregate( { $unwind: "$descriptors.carDescriptor.entries" }, {$project: {make: "$descriptors.carDescriptor.entries.make", model: "$descriptors.carDescriptor.entries.model", firstName:"$firstName", lastName: "$lastName"}}, {$group: {_id: "$make"}} ) {code} Equivalent Spring Data representation {code} Aggregation agg = Aggregation.newAggregation( unwind("descriptors.carDescriptor.entries"), project() .and("descriptors.carDescriptor.entries.make").as("make") .and("descriptors.carDescriptor.entries.model").as("model") .and("firstName").as("firstName") .and("lastName").as("lastName"), group("make") ); {code} While the Mongo Shell query work fine, Spring MongoTemplate form does not and returns the following error {noformat} java.lang.IllegalArgumentException: Invalid reference 'make'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:92) at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62) at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:292) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1323) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1306) at com.example.samples.MongoTemplateTest.testAggregation(MongoTemplateTest.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {noformat} Pojo classes {code} // getter, setter omitted @Document public class Person { @Id private String id; private String firstName; private String lastName; private Descriptors descriptors; } public class Descriptors { private CarDescriptor carDescriptor; } public class CarDescriptor { private List<Entry> entries; class Entry { private String make; private String model; private int year; } } {code} To confirm if "make" is being returned remove the group("make") operator from the fluent api and the output shows that the make is indeed being returned. Any pointers / work arounds ? Thank you, Adil Fulara

    Spring JIRA | 3 years ago | Adil Fulara
    java.lang.IllegalArgumentException: Invalid reference 'make'!
  3. 0

    Ternary operator not supported in aggregation projection expressions?

    Stack Overflow | 3 years ago | Rob Worsnop
    java.lang.IllegalArgumentException: Unsupported Element: org.springframework.data.mongodb.core.spel.ExpressionNode@76c423f9 Type: class org.springframework.data.mongodb.core.spel.ExpressionNode You probably have a syntax error in your SpEL expression!
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I have the following mongodb document: {code:javascript} { "cmsParameterId":1, "examples":null, "rules":[ { "ruleType":"CODED", "values":[ "abc", "efg" ] }, { "ruleType":"SEQUENCE", "sequence":[ { "value":"a", "type":"CONSTANT" }, { "value":"2", "type":"PARAMETER" } ] } ] } {code} I use the following query in mongo shell which works fine. {code:javascript} db.domainknowledge.aggregate([ { $match: {cmsParameterId: { $in: [1] } } }, { $project: { cmsParameterId : 1 , rules : 1 }}, { $unwind: "$rules" }, { $group: { _id: { cmsParameterId: "$cmsParameterId", ruleType: "$rules.ruleType"}, total: { $sum: 1 } } } ]); {code} using spring-data I have written the following code to produce the same result but it ends up in an Exception: {code:java} Aggregation agg = newAggregation(match(Criteria.where("cmsParameterId").in(1)), project("cmsParameterId", "rules"), unwind("rules"), group("cmsParameterId", "rules.ruleType").count().as("totol")); AggregationResults<Summary> aggregate = mongoTemplate.aggregate(agg, "domainknowledge", Summary.class); {code} Here is the stacktrace of exception: {code:xml} java.lang.IllegalArgumentException: Invalid reference 'rules.ruleType'! at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:78) at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62) at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:300) at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1405) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1346) at com.etilize.automation.dke.core.domainknowledge.report.DomainKnowledgeReportServiceImpl.generateCategoryWiseReport(DomainKnowledgeReportServiceImpl.java:57) {code}

    Spring JIRA | 3 years ago | Faisal Feroz
    java.lang.IllegalArgumentException: Invalid reference 'rules.ruleType'!
  6. 0

    It would be useful if ternary operators were supported in aggregation projection expressions. For example: {code} Aggregation.project("from", "to").andExpression( "from == [0] ? to : from", "jdoe").as("correspondent")}} {code} At the moment I'm seeing an exception when I call aggregate: {code} java.lang.IllegalArgumentException: Unsupported Element: org.springframework.data.mongodb.core.spel.ExpressionNode@76c423f9 Type: class org.springframework.data.mongodb.core.spel.ExpressionNode You probably have a syntax error in your SpEL expression! at org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.lookupConversionFor(SpelExpressionTransformer.java:124) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.transform(SpelExpressionTransformer.java:105) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.SpelExpressionTransformer.transform(SpelExpressionTransformer.java:97) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.ProjectionOperation$ExpressionProjectionOperationBuilder$ExpressionProjection.toMongoExpression(ProjectionOperation.java:336) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.ProjectionOperation$ExpressionProjectionOperationBuilder$ExpressionProjection.toDBObject(ProjectionOperation.java:332) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.ProjectionOperation.toDBObject(ProjectionOperation.java:187) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:317) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1412) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1347) ~[spring-data-mongodb-1.6.0.RELEASE.jar:na] {code}

    Spring JIRA | 3 years ago | Rob Worsnop
    java.lang.IllegalArgumentException: Unsupported Element: org.springframework.data.mongodb.core.spel.ExpressionNode@76c423f9 Type: class org.springframework.data.mongodb.core.spel.ExpressionNode You probably have a syntax error in your SpEL expression!

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid reference 'make'!

      at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference()
    2. Spring Data MongoDB - Core
      MongoTemplate.aggregate
      1. org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:92)
      2. org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:62)
      3. org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:292)
      4. org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:247)
      5. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1323)
      6. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1306)
      6 frames
    3. com.example.samples
      MongoTemplateTest.testAggregation
      1. com.example.samples.MongoTemplateTest.testAggregation(MongoTemplateTest.java:82)
      1 frame
    4. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      3 frames
    5. JUnit
      InvokeMethod.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      4 frames
    6. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      2. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      3. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      4. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      5. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
      5 frames
    7. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      5 frames
    8. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      2 frames
    9. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      1 frame
    10. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      1 frame
    11. JUnit
      JUnitCore.run
      1. org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      1 frame
    12. IntelliJ junit4 module
      JUnit4IdeaTestRunner.startRunnerWithArgs
      1. com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
      1 frame
    13. IDEA
      JUnitStarter.main
      1. com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
      2. com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
      2 frames
    14. Java RT
      NativeMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      2 frames
    15. IDEA
      AppMain.main
      1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      1 frame