simou
simou

Reputation: 2506

QueryDsl, combining standard JPA and Hibernate's - class level @Where annotations?

I'm wondering if I could team up hibernate annotations, and particularly those class level annotations, with standard JPA annotations in QueryDsl. Like so...

 @javax.persistence.Entity
 @org.hibernate.annotations.Where(clause="someProperty = (SELECT ....)")
 @javax.persistence.Table(name="anyname")
 public class SomeClass {...
 }

Currently we use JPA annotations only but we must incorporate some hibernate annotations as well.

Is is safe to replace "JPAAnnotationProcessor" by "HibernateAnnotationProcessor" in the apt plug-in configuration? *)

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.0.8</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                          <processor>com.mysema.query.apt.hibernate.HibernateAnnotationProcessor</processor>
                        <sourceDirectory>src/gen/java</sourceDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

*) However after replacing the annotation-processor to "HibernateAnnotationProcessor" I couldn't notice any change in the resulting JPA Query. Is it because I'm still using JPA which apparently doesn't acknowledge any hibernate specifics?

  JPAQuery query = new JPAQuery (this.emf.createEntityManager());

Do I need to switch to Hibernate Session as well?

Upvotes: 2

Views: 1011

Answers (1)

Timo Westk&#228;mper
Timo Westk&#228;mper

Reputation: 22190

Querydsl uses HibernateAnnotationProcessor just to decide if there are relevant annotations in fields and/or methods.

If only fields are annotated, then they are used as properties, and if only getters are annotated, those are used instead. If both are used, getter info overrides field info.

For class level annotations it makes no difference if you use one processor or the other, if your classes are primarily annotated with the JPA annotations.

The used annotation processor doesn't effect how your entity types are treated in the JPAQuery.

Upvotes: 1

Related Questions