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

Criteria throwing a lot of PropertyReferenceException #4875

Closed
felipe-issa-zebra opened this issue Jan 15, 2025 · 3 comments
Closed

Criteria throwing a lot of PropertyReferenceException #4875

felipe-issa-zebra opened this issue Jan 15, 2025 · 3 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid

Comments

@felipe-issa-zebra
Copy link

felipe-issa-zebra commented Jan 15, 2025

Our app uses Spring boot 3.3.6 and have the following scenario:

Model:

@Document(collection = "STORAGE_CLASS")
public class StorageClass {

    @Field("STATUS")
    private String status;

    @Field("FIELD_NUMBER")
    private long numberField;

    ... // getters, setters, tostring
}

We need to query this collection on database every 10 seconds, so we wrote a dao for it:

public interface StorageClassDao {
    List<StorageClass> getStorage();
}
@Repository
public class StorageClassDaoImpl implements StorageClassDao {
    private MongoTemplate mongoTemplate;
    public StorageClassDaoImpl(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }

    @Override
    public List<StorageClass> getStorage() {
        Criteria criteria = Criteria.where("STATUS").is("E")
            .and("FIELD_NUMBER").is(1);
        Query query = new Query(criteria);
        return this.mongoTemplate.find(query, StorageClass.class);
    }
}

This works, I receive data from getStorage which matches the query I passed. However I see a lot of PropertyReferenceException are being thrown (If I add a breakpoint to this exception), with the messages as follows:

  • No property 'STATUS' found for type 'StorageClass'
  • No property 'STATU' found for type 'StorageClass'
  • No property 'STAT' found for type 'StorageClass'
  • No property 'STA' found for type 'StorageClass'
  • No property 'ST' found for type 'StorageClass'
  • No property 's' found for type 'StorageClass'
  • No property 'FIELD' found for type 'StorageClass'
  • No property 'FIEL' found for type 'StorageClass'
  • No property 'FIE' found for type 'StorageClass'
  • No property 'FI' found for type 'StorageClass'
  • No property 'f' found for type 'StorageClass'
  • No property 'FIELD_NUMBER' found for type 'StorageClass'
  • No property 'FIELD_NUMBE' found for type 'StorageClass'
  • No property 'FIELD_NUMB' found for type 'StorageClass
  • No property 'FIELD_NUM' found for type 'StorageClass'
  • No property 'FIELD_NU' found for type 'StorageClass'
  • No property 'FIELD_N' found for type 'StorageClass''
  • No property 'FIELD_' found for type 'StorageClass'

The exceptions are throwed manly from two places:

  • Exception 'org.springframework.data.mapping.PropertyReferenceException' occurred in thread 'scheduling-1' at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:490)
  • Exception 'org.springframework.data.mapping.PropertyReferenceException' occurred in thread 'scheduling-1' at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:94)

For every service call, more than 100 of this exceptions are being throwed. On our actual app, more than 100k exception are being throwed / GC, which is consuming a lot of unecessary resources.

What am I doing wrong here?

Code for reference: https://github.com/felipeissa/mongo-db-exception

Spring boot version: 3.3.6
Spring data mongodb version: 4.3.6
Java version: 21

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 15, 2025
@christophstrobl
Copy link
Member

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Data MongoDB uses domain type information to map fields to their field names considering @Field annotations. Please use property names from your java type. something like Criteria.where("status").is("E").and("numberField").is(1);

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@christophstrobl christophstrobl added status: invalid An issue that we don't feel is valid status: waiting-for-triage An issue we've not yet triaged for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 15, 2025
@felipe-issa-zebra
Copy link
Author

Hey @christophstrobl , I've done it one month ago, and had no answer there, thats why I oepened it here as a bug (there seems to be no way around this many exceptions).

https://stackoverflow.com/questions/79271811/mongodb-query-on-spring-data-and-propertyreferenceexception

@christophstrobl
Copy link
Member

just make sure to use the property names from the domain model. We've an open ticket (spring-projects/spring-data-commons#3220) that aims at improving the path resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants