Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate query-dsl Q classes on external entity?

I make use of an @Entity class from a commons library:

@Entity
public class Person {
    @Id
    private long id;

    private String firstname;
    
    @NotNull
    private String lastname;
}

In my impl application, I want to generated a QPerson querydsl entity. But how? Because I have no control over the commons library, I cannot simply add the @QueryEntity annotation for the querydsl processor.

like image 436
membersound Avatar asked Oct 24 '25 14:10

membersound


1 Answers

I found a solution. Yet I don't know if that's the correct way, so would be still happy for your comments.

Create a package-info somewhere in the implementation project as follows:

@QueryEntities(value = {Person.class})
package my.impl.project

What is strange: now all of the entity classes from the commons project get generated. Therefore I restricted the path in maven:

<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>
                <options>        
                    <querydsl.includedPackages>org.common.domain.person</querydsl.includedPackages>
                </options>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
    </dependencies>
</plugin>
like image 75
membersound Avatar answered Oct 27 '25 04:10

membersound



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!