membersound
membersound

Reputation: 86747

How to skip @Transient fields in querydsl generation?

I have an @Entity class that I use querydsl code generation on.

Problem: my entity has a parent entity which contains some @Transient fields. And those are not skipped during generation.

package com.domain.myentity

@Entity
public class MyEntity extends AuditingEntity {

}


package com.auditing

@MappedSuperclass
public class AuditingEntity {
    @Transient
    private transient Object obj;
}

package-info.java:

@QueryEntities(value = MyEntity.class)
package com.domain.myentity

import com.querydsl.core.annotations.QueryEntities;
import com.domain.myentity.MyEntity;

Question: how can I tell querydsl to ignore any @Transient fields automatically? Currently the root cause is probably that the AuditingEntity is in a different folder than the domain entity, and therefore not listed in the package-info.java of querydsl. But how could I solve it without having to move the auditing entity?

Generated during:

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>${apt-maven-plugin.version}</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
    </dependencies>
</plugin>

Upvotes: 0

Views: 2736

Answers (2)

user7906470
user7906470

Reputation:

If you want to prevent QueryDsl from mapping a field or method you should use the @QueryType - annotation with PropertyType.NONE.

The value PropertyType.NONE can be used to skip a property in the query type generation. This case is different from @Transient or @QueryTransient annotated properties, where properties are not persisted. PropertyType.NONE just omits the property from the Querydsl query type.

@Entity
public class MyEntity {


    @QueryType(PropertyType.NONE)
    public String stringNotInQuerydsl;

}

See the official documentation here

Upvotes: 1

Er&#231;in Ak&#231;ay
Er&#231;in Ak&#231;ay

Reputation: 1423

Could you try transient declaration as transient String obj; instead of

@Transient
private Object obj;

Upvotes: 3

Related Questions