querydsl / apt-maven-plugin

Maven APT plugin
Apache License 2.0
79 stars 41 forks source link

apt plugin not generating correct Q type through Eclipse IDE (for new Java time/date types) #45

Closed anojan981 closed 9 years ago

anojan981 commented 9 years ago

Hi,

Recently, I have started playing around with using the new Java 8 time/date classes in my hibernate models.

So, let's say I have a hibernate model that has the following field

OffsetDateTime lastUpdated;

When I perform a maven build, the Q type for the model is generated with the correct field which looks like:

public final DateTimePath<java.time.OffsetDateTime> lastUpdated = createDateTime("lastUpdated", java.time.OffsetDateTime.class);

But when I build via Eclipse IDE (I'm on Luna), the Q type has the following, which is incorrect:

public final NumberPath<OffsetDateTime> lastUpdated = createNumber("lastUpdated", OffsetDateTime.class);

You can see it is using NumberPath instead of DateTimePath. Moreover, the fully qualified path for OffsetDateTime is lost and the import for OffsetDateTime is not generated leading to compile errors in Eclipse.

For now, my work around is to compile in Maven and refresh in Eclipse, but its a pain to deal with as when Eclipse re-compiles, the compile errors return.

Please advise if there is a solution for this?

Here is my querydsl dependencies and apt plugin configuration:

        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>4.0.4</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>4.0.4</version>
        </dependency>

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Thank you very much

Shredder121 commented 9 years ago

The apt plugin does nothing more than integrate with the Annotation Processor API, This leads me to believe that either there is a bug in our annotation processor (com.querydsl.apt.jpa.JPAAnnotationProcessor), which is in the querydsl codebase, or Eclipse, since annotation processing is a compiler thing, which eclipse handles on its own.

Could you maybe make an example project with that configuration? I think I have an Eclipse IDE Luna version downloaded.

anojan981 commented 9 years ago

Sure, I'll put something together for you.

anojan981 commented 9 years ago

I've placed a sample project that exhibits the same behaviour here: sample-apt.zip

Simply unzip and import into Eclipse Luna (I'm using version: Luna Service Release 1 (4.4.1)) as a maven import. The project contains only one JPA entity class.

If you run a 'mvn package', you will see that the Q type for the entity is generated perfectly fine.
However, if you build it in Eclipse, the Q type will be incorreclty generated.

Ensure to set your JAVA_HOME to JDK 8 (I'm using Oracle JDK 8 build 1.8.0_40) before running the maven build.

Thank you and let me know if there are any issues downloading the file.

Shredder121 commented 9 years ago

Could you maybe tell me how to build it in Eclipse so that it fails? I see that running it as maven generate-sources goes good, but Project > Clean also goes good on my side. I am trying with Oracle JDK build 1.8.0_60, and also tried Openjdk build 1.8.0_45. I have Eclipse Luna Service Release 2 (4.4.2) downloaded.

anojan981 commented 9 years ago

Hmm, I simply import the project and perform a clean build. The resulting Q types are incorrectly generating. There is nothing apart from the ordinary that I am doing. Perhaps it is the version of Eclipse I am on which is Luna Service Release 1 (4.4.1).

I'll retry with 4.4.2

Thanks

Shredder121 commented 9 years ago

Let me know if you find a way to reproduce or if you don't encounter the issue anymore.

johnktims commented 9 years ago

@anojan981, I'm going to close this for now. If this is still a problem, feel free to comment and we'll reopen it.

anojan981 commented 9 years ago

Sure that's fine. I still have the issue but I haven't yet had a chance to try with Shredder121's setup. Hoping to try it out in Nov and will post back with my findings.

Thanks.

Shredder121 commented 9 years ago

For reference, I have opened this project in an entirely different setup: https://codenvy.com/ws/rubendijkstra123/sample-apt

This also generates the right sources. https://codenvy.com/api/builder/workspaceae9swohdzxea4g90/view/21649?path=target/generated-sources/java/com/querydsl/sample/apt/model/feedback/QCustomerFeedback.java

package com.querydsl.sample.apt.model.feedback;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;

/**
 * QCustomerFeedback is a Querydsl query type for CustomerFeedback
 */
@Generated("com.querydsl.codegen.EntitySerializer")
public class QCustomerFeedback extends EntityPathBase<CustomerFeedback> {

    private static final long serialVersionUID = 819389446L;

    public static final QCustomerFeedback customerFeedback = new QCustomerFeedback("customerFeedback");

    public final StringPath clientHost = createString("clientHost");

    public final StringPath content = createString("content");

    public final NumberPath<java.math.BigDecimal> id = createNumber("id", java.math.BigDecimal.class);

    public final StringPath ipAddress = createString("ipAddress");

    public final DateTimePath<java.time.OffsetDateTime> lastUpdated = createDateTime("lastUpdated", java.time.OffsetDateTime.class);

    public QCustomerFeedback(String variable) {
        super(CustomerFeedback.class, forVariable(variable));
    }

    public QCustomerFeedback(Path<? extends CustomerFeedback> path) {
        super(path.getType(), path.getMetadata());
    }

    public QCustomerFeedback(PathMetadata metadata) {
        super(CustomerFeedback.class, metadata);
    }

}

I'll hear from you whenever you find something.

anojan981 commented 9 years ago

Hi, I just wanted to add some closing comments.

I was finally able to upgrade to latest eclipse mars build (still using oracle jdk 1.8.0_40) and this problem vanished.

So it must have been an issue specific to my environment using eclipse luna 4.4.1.

Thanks very much for your help.

Cheers