Search code examples
jpaquerydsl

Generate Q-type from Class object in QueryDSL


I have a method which returns the Class object of entity I want to query:

protected abstract Class<T> getEntityClass();

and later I would like to query this entity with QueryDSL

new JPAQuery<>(em).from(?????);

how can I achieve this?


Solution

  • I've just found out I can use PathBuilder:

    PathBuilder<Person> pathBuilder = new PathBuilder(Person.class, "PERSON");
    
    List<Person> fetch = new JPAQuery<Person>(em)
                    .from(pathBuilder)
                    .fetch();