CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-mysema-querydsl--querydsl-apt

APT-based source code generation tool for Querydsl that generates type-safe query classes from annotated Java entity classes.

Pending
Overview
Eval results
Files

framework-processors.mddocs/

Framework-Specific Processors

Specialized annotation processors for different persistence frameworks, each handling framework-specific annotations and conventions while extending the core Querydsl processing capabilities.

Capabilities

JPA Annotation Processor

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-classes

Usage 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 type

Hibernate Annotation Processor

Extends 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:

  • Hibernate-specific annotations in org.hibernate.annotations.* package
  • Enhanced type mappings for Hibernate custom types
  • Support for Hibernate-specific naming strategies

JDO Annotation Processor

Processes 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 annotation

Usage 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;
}

Morphia Annotation Processor

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 annotation

MongoDB-Specific Features:

  • Custom type mapping for Double[] arrays to spatial Point types
  • Support for MongoDB document structure and embedded documents
  • NoSQL-appropriate query generation patterns

Usage 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;
}

Spring Roo Annotation Processor

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)
  • Standard JPA annotations: @MappedSuperclass, @Embeddable, @Embedded, @Transient

Roo Integration Features:

  • Dual entity annotation support (primary: @RooJpaEntity, alternative: @RooJpaActiveRecord)
  • Integration with Roo's Active Record pattern
  • Compatible with Roo's code generation and AspectJ weaving

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;
}

Service Registration

All processors are automatically registered via the Java Service Provider Interface using META-INF/services files:

META-INF/services/javax.annotation.processing.Processor

Registration Files:

  • general/: com.mysema.query.apt.QuerydslAnnotationProcessor
  • jpa/: com.mysema.query.apt.jpa.JPAAnnotationProcessor
  • hibernate/: com.mysema.query.apt.hibernate.HibernateAnnotationProcessor
  • jdo/: com.mysema.query.apt.jdo.JDOAnnotationProcessor
  • morphia/: com.mysema.query.apt.morphia.MorphiaAnnotationProcessor
  • roo/: com.mysema.query.apt.roo.RooAnnotationProcessor

This 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

docs

configuration.md

core-processing.md

framework-processors.md

index.md

processing-options.md

tile.json