Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rjokelai opened this issue Sep 28, 2012 · 5 comments
Assignees

Comments

@rjokelai
Copy link

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>
@ghost ghost assigned timowest Sep 28, 2012
timowest added a commit that referenced this issue Sep 28, 2012
@timowest
Copy link
Member

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

}

@rjokelai
Copy link
Author

rjokelai commented Oct 1, 2012

Thanks for the pointer, got it working!

@philippeboyd
Copy link

Wow! Thanks @timowest

@jomach
Copy link

jomach commented Jun 30, 2017

Wow ! It really works ! Thanks @timowest

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

@guilhermeandraschko
Copy link

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

}

This worked for me. I think that maybe a solution where we can mark some hibernate entity to be ignored by jpa query dsl processor would be good as well. Because in this case, normally I don't think audited tables will have use case with query dsl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants