I am using QueryDSL with Spring Data JPA in my Java Project and have Generated files using QueryDSL maven plugin to use the QueryDSL Model classes generated by it. This works great when i use it for one level nested objects, however if i try to access the 2nd level access objects it gives a NullPointerException saving the 2nd level model object is not initialized.
Would appreciate some help.
I am getting a NullPointerException in 3rd line qmachine.vendor is null.
QTransaction qtransaction = QTransaction.transaction;
QMachine qmachine = qtransaction.machine;
BooleanExpression vendorexp = qmachine.vendor.vendor.eq(machineType);
My Mapping classes are below: Transaction
@Entity
@Table(name = "dsdsd")
public class Transaction extends AbstractPersistable<Long> {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "machine_id")
private Machine machine;
}
And the Machine class is :
@Entity
@Table(name="machine")
public class Machine extends AbstractPersistable<Long> {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name="vendor_id")
private Vendor vendor;
}
and the Vendor class is
@Entity
@Table(name="vendors")
public class Vendor extends AbstractPersistable<Long> {
private static final long serialVersionUID = 1L;
@Column(name="vendor")
@Enumerated(EnumType.STRING)
private VendorType vendor;
}
I have ommitted the getters and setters intentionally.
By default only the first level is initialized. See this documentation section for initialization options : http://www.querydsl.com/static/querydsl/3.6.0/reference/html/ch03s03.html#d0e2192
Full deep initialization is not possible with final fields, because of the possibility of infinite loops, but Querydsl provides also the option of property accessor methods.