question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@QueryInit not working with deep nested paths

See original GitHub issue

I am using QueryDSL 4.1.4 with Spring Data in a project and am having trouble using it with nested paths. Consider the following JPA classes:

@Entity @QueryEntity class Company {}

@Entity
@QueryEntity
class Contract {
  @ManyToOne
  @QueryInit("*.*")
  Company buyer;

  @ManyToOne
  @QueryInit("*.*")
  Company seller;
}

@Entity @QueryEntity class Bill { @ManyToOne @QueryInit("*.*") Contract contract; }

@Entity @QueryEntity class Payment { @ManyToOne @QueryInit("*.*") Bill bill; }

@Entity @QueryEntity class Posting { @ManyToOne @QueryInit("*.*") Payment payment; }

With this set up, the following throws NullPointerException:

QPosting.posting.payment.bill.contract.buyer.name.equalsIgnoreCase(...)

Debugging shows that QPosting.posting.payment.bill.contract.buyer (and QPosting.posting.payment.bill.contract.seller) is null.

The following however work fine:

  1. QPayment.payment.bill.contract.buyer.name.equalsIgnoreCase(...)
  2. QBill.bill.contract.buyer.name.equalsIgnoreCase(...)
  3. QContract.contract.buyer.name.equalsIgnoreCase(...)

I am using com.mysema.maven:apt-maven-plugin:1.1.1 and QueryDSL version 4.1.4.

A full sample project is available here. Run Maven tests as mvn clean test to see the error.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
FranPregernikcommented, Sep 19, 2017

I just encountered the same issue in my model.

I get a NullPointerException when calling upisaniPredmet.upisaniElement.upis.student.

upisaniPredmet.upisaniElement is not null. upisaniPredmet.upisaniElement.upis is not null. upisaniPredmet.upisaniElement.upis.student is null.

3reactions
mosekkcommented, May 7, 2018

I have exactly the same problem. Must be the bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring - How to use @QueryInit to init path to attribute of ...
Has anyone use @QueryInit to fix a problem similar to mine ? ... b.a.id and a.amount <= sum(b.amount))]; nested exception is java.lang.
Read more >
Null property in metadata for nested entities - Launchpad Bugs
You can declare via annotations which deep paths are to be initialized or use accessor methods for entity references.
Read more >
What Can Querydsl Do for Me Part 2: Multi-Tenant Application ...
Now that we know the problem and have a better understanding of initialization path limitations in Querydsl, we have a one-line fix to...
Read more >
3.2. Configuration - Querydsl
In cases where longer initialization paths are required, these have to be ... QueryInit is used on properties where deep initializations are needed....
Read more >
Query with multiple nested filter on same path not working
I have a query where there are 2 nested filters as follows (generated via Java API): GET pay/_search { "size" : 1000, "query"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found