Querydsl: Code generation for class extending Hibernate Envers DefaultRevisionEntiry fails with JPAAnnotationProcessor when using JPA/Hibernate and Hibernate Envers

Created on 28 Sep 2012  ·  4Comments  ·  Source: querydsl/querydsl

My model classes are annotated with JPA's @Entity annotation. All other classes are generated fine, except the one extending Hibernate Envers' DefaultRevisionEntity. The code generation fails with the following error during mvn clean test

/.../target/generated-sources/java/.../QRevision.java:[23,37] cannot find symbol
symbol  : class QDefaultRevisionEntity
location: package org.hibernate.envers
/.../target/generated-sources/java/.../QRevision.java:[23,94] cannot find symbol
symbol  : class QDefaultRevisionEntity
location: package org.hibernate.envers
Revision.java:
import javax.persistence.Entity;

import org.hibernate.envers.DefaultRevisionEntity;
import org.hibernate.envers.RevisionEntity;

@Entity
@RevisionEntity(CustomRevisionListener.class)
public class Revision extends DefaultRevisionEntity {
    // Fields are irrelevant
}
pom.xml
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>2.7.3</version>
</dependency>
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>2.7.3</version>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.0.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                        <excludes>
                            <exclude>com.itella.ptp.model.Revision</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>2.7.3</version>
                </dependency>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-jpa</artifactId>
                    <classifier>apt</classifier>
                    <version>2.7.3</version>
                </dependency>
            </dependencies>
        </plugin>
        ...
    </plugins>
</build>

Most helpful comment

References to external annotated entity types are expected to have the Q-types already available in the classpath.

To enforce the generation of of QDefaultRevisionEntity you can add the following annotation into a package-info.java file

@QueryEntities({DefaultRevisionEntity.class})
package com.example.domain;

import org.hibernate.envers.DefaultRevisionEntity;
import com.mysema.query.annotations.QueryEntities;

This will get you QDefaultRevisionEntity.java with the following contents

package org.hibernate.envers;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.*;
import com.mysema.query.types.path.*;

import javax.annotation.Generated;


/**
 * QDefaultRevisionEntity is a Querydsl query type for DefaultRevisionEntity
 */
@Generated("com.mysema.query.codegen.EmbeddableSerializer")
public class QDefaultRevisionEntity extends BeanPath<DefaultRevisionEntity> {

    private static final long serialVersionUID = -546101328;

    public static final QDefaultRevisionEntity defaultRevisionEntity = new QDefaultRevisionEntity("defaultRevisionEntity");

    public final NumberPath<Integer> id = createNumber("id", Integer.class);

    public final DateTimePath<java.util.Date> revisionDate = createDateTime("revisionDate", java.util.Date.class);

    public final NumberPath<Long> timestamp = createNumber("timestamp", Long.class);

    public QDefaultRevisionEntity(String variable) {
        super(DefaultRevisionEntity.class, forVariable(variable));
    }

    public QDefaultRevisionEntity(Path<? extends DefaultRevisionEntity> path) {
        super(path.getType(), path.getMetadata());
    }

    public QDefaultRevisionEntity(PathMetadata<?> metadata) {
        super(DefaultRevisionEntity.class, metadata);
    }

}

All 4 comments

References to external annotated entity types are expected to have the Q-types already available in the classpath.

To enforce the generation of of QDefaultRevisionEntity you can add the following annotation into a package-info.java file

@QueryEntities({DefaultRevisionEntity.class})
package com.example.domain;

import org.hibernate.envers.DefaultRevisionEntity;
import com.mysema.query.annotations.QueryEntities;

This will get you QDefaultRevisionEntity.java with the following contents

package org.hibernate.envers;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.*;
import com.mysema.query.types.path.*;

import javax.annotation.Generated;


/**
 * QDefaultRevisionEntity is a Querydsl query type for DefaultRevisionEntity
 */
@Generated("com.mysema.query.codegen.EmbeddableSerializer")
public class QDefaultRevisionEntity extends BeanPath<DefaultRevisionEntity> {

    private static final long serialVersionUID = -546101328;

    public static final QDefaultRevisionEntity defaultRevisionEntity = new QDefaultRevisionEntity("defaultRevisionEntity");

    public final NumberPath<Integer> id = createNumber("id", Integer.class);

    public final DateTimePath<java.util.Date> revisionDate = createDateTime("revisionDate", java.util.Date.class);

    public final NumberPath<Long> timestamp = createNumber("timestamp", Long.class);

    public QDefaultRevisionEntity(String variable) {
        super(DefaultRevisionEntity.class, forVariable(variable));
    }

    public QDefaultRevisionEntity(Path<? extends DefaultRevisionEntity> path) {
        super(path.getType(), path.getMetadata());
    }

    public QDefaultRevisionEntity(PathMetadata<?> metadata) {
        super(DefaultRevisionEntity.class, metadata);
    }

}

Thanks for the pointer, got it working!

Wow! Thanks @timowest

Wow ! It really works ! Thanks @timowest

I only have @Entity on my code and it still works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmpicnic picture jmpicnic  ·  7Comments

viktorgt picture viktorgt  ·  3Comments

aoudiamoncef picture aoudiamoncef  ·  3Comments

svaidya401 picture svaidya401  ·  4Comments

timowest picture timowest  ·  7Comments