3.4. Inheritance in Querydsl types

To avoid a generic signature in Querydsl query types the type hierarchies are flattened. The result is that all generated query types are direct subclasses of com.mysema.query.types.path.PEntity and cannot be directly cast to their Querydsl supertypes.

Instead of a direct Java cast, the supertype reference is accessible via the _super field. A _super-field is available in all query types with a single supertype :

// from Account
QAccount extends PEntity<Account>{
    // ...
}

// from BankAccount extends Account
QBankAccount extends PEntity<BankAccount>{

    public final QAccount _super = new QAccount(this);
    
    // ...
}            

To cast from a supertype to a subtype you can use the as-method of the PEntity class :

QAccount account = new QAccount("account");
QBankAccount bankAccount = account.as(QBankAccount.class);