APT-based source code generation tool for Querydsl that generates type-safe query classes from annotated Java entity classes.
—
Specialized annotation processors for different persistence frameworks, each handling framework-specific annotations and conventions while extending the core Querydsl processing capabilities.
Processes JPA (Java Persistence API) annotations to generate type-safe query classes for JPA entities.
/**
* Annotation processor for JPA entities
* Handles @Entity, @MappedSuperclass, @Embeddable, @Embedded, @Transient
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*","javax.persistence.*"})
public class JPAAnnotationProcessor extends AbstractQuerydslProcessor {
/**
* Creates JPA-specific configuration
* @param roundEnv Processing environment
* @return JPAConfiguration with JPA annotation mappings
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv);
}
/**
* JPA-specific configuration extending DefaultConfiguration
*/
public class JPAConfiguration extends DefaultConfiguration {
public JPAConfiguration(RoundEnvironment roundEnv, Map<String,String> options,
Class<? extends Annotation> entity,
Class<? extends Annotation> superType,
Class<? extends Annotation> embeddable,
Class<? extends Annotation> embedded,
Class<? extends Annotation> skip);
}Supported JPA Annotations:
@Entity: JPA entity classes → generates Q-classes@MappedSuperclass: JPA mapped superclasses → generates supertype Q-classes@Embeddable: JPA embeddable classes → generates embeddable Q-classes@Embedded: JPA embedded properties → processed as embedded types@Transient: JPA transient properties → excluded from Q-classesUsage Example:
import javax.persistence.*;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "username", nullable = false)
private String username;
@Embedded
private Address address;
@Transient // Excluded from QUser
private String temporaryData;
}
@Embeddable
public class Address {
private String street;
private String city;
private String zipCode;
}
// Generates:
// - QUser.java with id, username, and address properties
// - QAddress.java for the embeddable typeExtends JPA processing with Hibernate-specific annotations and features.
/**
* Hibernate annotation processor extending JPA support
* Handles JPA annotations plus Hibernate-specific annotations
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*","javax.persistence.*", "org.hibernate.annotations.*"})
public class HibernateAnnotationProcessor extends JPAAnnotationProcessor {
/**
* Creates Hibernate-specific configuration with additional Hibernate support
* @param roundEnv Processing environment
* @return HibernateConfiguration with Hibernate annotation support
* @throws ClassNotFoundException if Hibernate classes not found
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv) throws ClassNotFoundException;
}
/**
* Hibernate-specific configuration
*/
public class HibernateConfiguration extends JPAConfiguration {
public HibernateConfiguration(RoundEnvironment roundEnv, Map<String,String> options, ...);
}Additional Hibernate Support:
org.hibernate.annotations.* packageProcesses JDO (Java Data Objects) annotations for generating query classes from JDO persistent classes.
/**
* Annotation processor for JDO entities
* Handles @PersistenceCapable, @EmbeddedOnly, @NotPersistent
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*","javax.jdo.annotations.*"})
public class JDOAnnotationProcessor extends AbstractQuerydslProcessor {
/**
* Creates JDO-specific configuration
* @param roundEnv Processing environment
* @return JDOConfiguration with JDO annotation mappings
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv);
}
/**
* JDO-specific configuration
*/
public class JDOConfiguration extends DefaultConfiguration {
public JDOConfiguration(RoundEnvironment roundEnv, Map<String,String> options,
Class<? extends Annotation> entities,
Class<? extends Annotation> entity,
Class<? extends Annotation> superType,
Class<? extends Annotation> embeddable,
Class<? extends Annotation> embedded,
Class<? extends Annotation> skip);
}Supported JDO Annotations:
@PersistenceCapable: JDO persistent classes → generates Q-classes@EmbeddedOnly: JDO embeddable classes → generates embeddable Q-classes@NotPersistent: JDO non-persistent fields → excluded from Q-classes@QueryEntities: Package-level entity listing (Querydsl annotation)@QuerySupertype: Querydsl supertype annotation@QueryEmbedded: Querydsl embedded annotationUsage Example:
import javax.jdo.annotations.*;
import com.mysema.query.annotations.QueryEmbedded;
@PersistenceCapable
public class Customer {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long customerId;
@Persistent
private String customerName;
@QueryEmbedded
@Persistent(embedded = "true")
private ContactInfo contact;
@NotPersistent // Excluded from QCustomer
private String cachedData;
}Processes MongoDB Morphia annotations for NoSQL document-based entities.
/**
* Annotation processor for MongoDB Morphia entities
* Handles @Entity, @Embedded, @Transient from Morphia framework
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*","org.mongodb.morphia.annotations.*"})
public class MorphiaAnnotationProcessor extends AbstractQuerydslProcessor {
/**
* Creates Morphia-specific configuration with MongoDB support
* @param roundEnv Processing environment
* @return DefaultConfiguration with Morphia annotation mappings and custom types
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv);
}Supported Morphia Annotations:
@org.mongodb.morphia.annotations.Entity: MongoDB entities → generates Q-classes@org.mongodb.morphia.annotations.Embedded: Embedded documents → embeddable Q-classes@org.mongodb.morphia.annotations.Transient: Transient fields → excluded from Q-classes@QueryEntities: Package-level entity listing (Querydsl annotation)@QuerySupertype: Querydsl supertype annotationMongoDB-Specific Features:
Double[] arrays to spatial Point typesUsage Example:
import org.mongodb.morphia.annotations.*;
import com.mysema.query.annotations.QuerySupertype;
@Entity("products")
public class Product {
@Id
private ObjectId id;
private String name;
private Double price;
@Embedded
private ProductDetails details;
@Transient // Excluded from QProduct
private String sessionData;
}
@Entity
@QuerySupertype
public abstract class BaseEntity {
@Id
protected ObjectId id;
protected Date created;
protected Date modified;
}Processes Spring Roo annotations for Active Record pattern entities.
/**
* Annotation processor for Spring Roo entities
* Handles @RooJpaEntity, @RooJpaActiveRecord plus standard JPA annotations
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*","javax.persistence.*","org.springframework.roo.addon.jpa.entity.*"})
public class RooAnnotationProcessor extends AbstractQuerydslProcessor {
/**
* Creates Roo-specific configuration supporting both Roo and JPA annotations
* @param roundEnv Processing environment
* @return JPAConfiguration with alternative entity annotation for Active Record
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv);
}Supported Roo Annotations:
@RooJpaEntity: Roo JPA entities → generates Q-classes@RooJpaActiveRecord: Roo Active Record entities → generates Q-classes (alternative)@MappedSuperclass, @Embeddable, @Embedded, @TransientRoo Integration Features:
@RooJpaEntity, alternative: @RooJpaActiveRecord)Usage Example:
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import javax.persistence.*;
@RooJpaEntity
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String author;
private Integer pages;
}
@RooJpaActiveRecord // Alternative entity annotation
@Entity
public class Author {
@Id
@GeneratedValue
private Long id;
private String name;
private String biography;
}All processors are automatically registered via the Java Service Provider Interface using META-INF/services files:
META-INF/services/javax.annotation.processing.ProcessorRegistration Files:
general/: com.mysema.query.apt.QuerydslAnnotationProcessorjpa/: com.mysema.query.apt.jpa.JPAAnnotationProcessorhibernate/: com.mysema.query.apt.hibernate.HibernateAnnotationProcessorjdo/: com.mysema.query.apt.jdo.JDOAnnotationProcessormorphia/: com.mysema.query.apt.morphia.MorphiaAnnotationProcessorroo/: com.mysema.query.apt.roo.RooAnnotationProcessorThis enables automatic processor discovery by the Java compiler and build tools without explicit configuration.
Install with Tessl CLI
npx tessl i tessl/maven-com-mysema-querydsl--querydsl-apt