Search code examples
javamavenjpaspring-rooquerydsl

Eclipse, QueryDSL and Spring Roo working together?


I'm trying to set up a maven-based SpringRoo project with QueryDSL in Eclipse and cannot seem to get the generator working when I have Roo enabled. If I create a plain project, and populate my pom.xml with the necessary querydsl plugins/dependencies, my metamodel classes are automatically generated.

However, if I switch to a basic ROO project, and add the necessary querydsl plugins/dependencies, then no metamodel classes are generated.

These are the additions I've put in my pom.xml:

<!-- Querydsl -->
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-core</artifactId>
    <version>${querydsl.version}</version>
</dependency>
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>${querydsl.version}</version>
</dependency>
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>${querydsl.version}</version>
</dependency>

    <plugin>
        <!-- Requires mysema m2e plugin (http://ilx.github.com/m2e-querydsl/repository/0.0.5/) -->
        <groupId>com.mysema.maven</groupId>
        <artifactId>maven-apt-plugin</artifactId>
        <version>1.0.4</version>
        <executions>
            <execution>
                <goals>
                    <goal>process</goal>
                </goals>
                <configuration>
                    <logOnlyOnError>true</logOnlyOnError>
                    <outputDirectory>target/generated-sources/apt</outputDirectory>
                    <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                </configuration>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>com.mysema.querydsl</groupId>
                <artifactId>querydsl-apt</artifactId>
                <version>${querydsl.version}</version>
            </dependency>
            <dependency>
                <groupId>com.mysema.querydsl</groupId>
                <artifactId>querydsl-jpa</artifactId>
                <classifier>apt</classifier>
                <version>${querydsl.version}</version>
            </dependency>
        </dependencies>
    </plugin>
    <!-- right now this seems needed -->

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <id>add-source</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>target/generated-sources/apt</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

I am using Eclipse 3.7, m2e 1.2, Java 6. I also have the mysema m2e plugin installed from http://ilx.github.com/m2e-querydsl/repository/0.0.5/.

Does anyone have a working configuration with Roo and QueryDSL that works? If so, can you share your pom.xml please?

Thanks,

Eric


Solution

  • For some reason that I do not understand, I needed to add a spring-tx dependency to my pom.xml. Once that was in place, the metamodel classes were automatically generated. There was a caveat however, I needed to manually annotate my entities with @Entity and not rely on Roo to annotate it via aspects. Finally, updating my plugin to 1.0.7 removed the need to use maven-build-helper.

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
    
            <!-- QueryDSL plugin -->
            <plugin>
            <!-- Requires mysema m2e plugin (http://ilx.github.com/m2e-querydsl/repository/0.0.5/) -->
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.0.7</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/apt</outputDirectory>
                        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>${querydsl.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-jpa</artifactId>
                    <classifier>apt</classifier>
                    <version>${querydsl.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    

    Sample Java Bean:

    @RooJavaBean
    @RooToString
    @RooJpaEntity
    @Entity
    public class Client {
        @Temporal(TemporalType.TIMESTAMP)
        @DateTimeFormat(style = "M-")
        private Date created_on;
        private String name;
    }