1

I am trying to create a subtype query along the following lines, but tyre is coming back as null even if I set @QueryInit("tyre") on the wheel property of car.

QWheel wheel = QCar.car.wheel;
QTyre tyre = wheel.as(QRoadWheel.class).tyre;    
BooleanExpression tyreFittedOverYearAgo 
    = tyre.fitted.lt(today.minusYears(1));
Iterable<Car> carsWithOldTyres = repo.findAll(tyreFittedOverYearAgo);

How do I get QueryDSL to initialise tyre when it is accessed using as()?

3
  • Which Querydsl version do you use? Commented Dec 21, 2015 at 20:56
  • Hi Timo, We're on 3.6.0. Commented Dec 22, 2015 at 8:55
  • By the way, I've just checked 3.7.0 and get the same problem. Commented Dec 22, 2015 at 9:15

2 Answers 2

2

By default Querydsl initializes only direct reference properties. In cases where longer initialization paths are required, these have to be annotated in the domain types via com.mysema.query.annotations.QueryInit usage. QueryInit is used on properties where deep initializations are needed.

@Entity      
class Event {
    @QueryInit("customer")
    Account account;
}      

@Entity
class Account{
    Customer customer;    
}

@Entity
class Customer{
    String name;
    String address;
} 

This will intialize customer.name ,customer.address

Sign up to request clarification or add additional context in comments.

1 Comment

You've not understood the question. I did say: 'even if I set @QueryInit("tyre")'
1

I've not been able to establish why, but I've now got things working but by using:

@QueryInit("*")
Tyre tyre;

1 Comment

This was indeed the solution? Seems counter to the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.