Problem with abstract fields and generics

Bug #816000 reported by Guillaume Smet
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Undecided
Unassigned

Bug Description

Hello,

We are currently evaluating QueryDSL to simplify and unify our access to the data layer (JPA2 and Hibernate Search) as its API looks really great.

We tried to use it on one of our projects, which are all based on a common framework.

The particularity of this framework is that we have a GenericEntity<K, E> class which has abstract methods for getId() and setId(). This causes problem and we can't get QueryDSL to generate classes with our setup.

You'll find 2 files attached built by one of my colleagues, Théo Chamley:

- the first sample project error-abstract-field-with-generics is a project with everything embedded in it. After a simple mvn package, you can see that QueryDSL has generated a class which does not compile. The QGenericEntity class contains the following line:
public final ComparablePath<> id = createComparable("id", .class);

- the second sample project (error-npe-external-jar-abstract-field-with-generics) is a bit more complicated. We have the problem if and only if the classes are in a separate jar so we added a local maven repository to the project (the local maven repository is in ./dependencies/maven and also contains the sources.jar).

When we use mvn package with this project, we have the following NPE:
java.lang.NullPointerException
 at com.mysema.query.codegen.TypeResolver.resolveTypeExtends(TypeResolver.java:54)
 at com.mysema.query.codegen.TypeResolver.resolve(TypeResolver.java:25)
 at com.mysema.query.codegen.Property.createCopy(Property.java:71)
 at com.mysema.query.codegen.EntityType.include(EntityType.java:187)
 at com.mysema.query.apt.Processor.addSupertypeFields(Processor.java:323)
 at com.mysema.query.apt.Processor.mergeTypes(Processor.java:418)
 at com.mysema.query.apt.Processor.process(Processor.java:471)
 at com.mysema.query.apt.Processor.processEntities(Processor.java:655)
 at com.mysema.query.apt.Processor.processAnnotations(Processor.java:176)
 at com.mysema.query.apt.Processor.process(Processor.java:124)
 at com.mysema.query.apt.jpa.JPAAnnotationProcessor.process(JPAAnnotationProcessor.java:50)
 at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)

Note that we use the latest version of QueryDSL (2.2.0 and maven-apt-plugin 1.0.2) and that these test cases are extracted from a real project. We had the second problem with our project and we found the first one while working on getting a simple test case.

Thanks for your feedback.

--
Guillaume

Revision history for this message
Guillaume Smet (guillaume-smet) wrote :
Revision history for this message
Guillaume Smet (guillaume-smet) wrote :
Changed in querydsl:
status: New → In Progress
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I commited some related fixes to SVN trunk. Could you try again?

Revision history for this message
Théo Chamley (theo-chamley) wrote :

Hello,
Thank you for your quick answer. The commit you just made did solve the first problem: the QGenericEntity class is now correctly generated.
However the second problem, the NullPointerException, remains unsolved. But the situation seams to have changed a little: an external jar is not required anymore to trigger the NPE.
In the attached file, you will find a simplified test case where we tried to minimize the number of class needed to see the problem.

We built querydsl from the SVN trunk, but we wondered if there was any other dependencies to re-build from another source than the main Maven repository. If so, could you tell us what do we have to re-build ?

Thank you for your help,

--

Théo Chamley

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Could you try again with SVN trunk?

> We built querydsl from the SVN trunk, but we wondered if there was any other dependencies to re-build from another source than the main Maven repository. If so, could you tell us what do we have to re-build ?

The other dependencies should be available from central public maven repos.

Revision history for this message
Théo Chamley (theo-chamley) wrote :
Download full text (4.4 KiB)

Thank you again. Your last modification made the last test case work.
Unfortunately the problem with the external jar is now back.

In fact we came across two problems that appear if and only if the classes GenericEntity and AbstractEntity are in an external jar.
 The first one is new and we discovered it trying to make a test case for the second one.

First: when AbstractEntity is annotated with an @MappedSuperClass, we get a new NPE (see the attached file error-npe-external-jar-abstract-field-with-generics-v2.tar.gz). But, even with this uncaught NPE, the building is a success:
java.lang.NullPointerException
 at com.mysema.query.apt.ExtendedTypeFactory.getSupertypes(ExtendedTypeFactory.java:409)
 at com.mysema.query.apt.ExtendedTypeFactory.createEntityType(ExtendedTypeFactory.java:319)
 at com.mysema.query.apt.ExtendedTypeFactory.getEntityType(ExtendedTypeFactory.java:288)
 at com.mysema.query.apt.ExtendedTypeFactory.createType(ExtendedTypeFactory.java:160)
 at com.mysema.query.apt.ExtendedTypeFactory.getType(ExtendedTypeFactory.java:151)
 at com.mysema.query.apt.ExtendedTypeFactory.createType(ExtendedTypeFactory.java:128)
 at com.mysema.query.apt.ExtendedTypeFactory.createClassType(ExtendedTypeFactory.java:207)
 at com.mysema.query.apt.ExtendedTypeFactory.handleDeclaredType(ExtendedTypeFactory.java:454)
 at com.mysema.query.apt.ExtendedTypeFactory.handle(ExtendedTypeFactory.java:434)
 at com.mysema.query.apt.ExtendedTypeFactory.createType(ExtendedTypeFactory.java:158)
 at com.mysema.query.apt.ExtendedTypeFactory.getType(ExtendedTypeFactory.java:151)
 at com.mysema.query.apt.ExtendedTypeFactory.getSupertypes(ExtendedTypeFactory.java:408)
 at com.mysema.query.apt.ExtendedTypeFactory.createEntityType(ExtendedTypeFactory.java:319)
 at com.mysema.query.apt.ExtendedTypeFactory.getEntityType(ExtendedTypeFactory.java:288)
 at com.mysema.query.apt.ExtendedTypeFactory.createType(ExtendedTypeFactory.java:160)
 at com.mysema.query.apt.ExtendedTypeFactory.getType(ExtendedTypeFactory.java:151)
 at com.mysema.query.apt.ExtendedTypeFactory.getSupertypes(ExtendedTypeFactory.java:408)
 at com.mysema.query.apt.ExtendedTypeFactory.getEntityType(ExtendedTypeFactory.java:280)
 at com.mysema.query.apt.Processor.process(Processor.java:447)
 at com.mysema.query.apt.Processor.processEntities(Processor.java:655)
 at com.mysema.query.apt.Processor.processAnnotations(Processor.java:177)
 at com.mysema.query.apt.Processor.process(Processor.java:125)
 at com.mysema.query.apt.jpa.JPAAnnotationProcessor.process(JPAAnnotationProcessor.java:50)

Second: when GenericEntity implements Serializable and Comparable, we get the NPE from the opening message (see the attached file error-npe-external-jar-abstract-field-with-generics-v3.tar.gz). Here, the building fails:
java.lang.NullPointerException
 at com.mysema.query.codegen.TypeResolver.resolveTypeExtends(TypeResolver.java:54)
 at com.mysema.query.codegen.TypeResolver.resolve(TypeResolver.java:25)
 at com.mysema.query.codegen.Property.createCopy(Property.java:71)
 at com.mysema.query.codegen.EntityType.include(EntityType.java:187)
 at com.mysema.query.apt.Processor.addSupertypeFields(Processor.java:324)
 at com.mysema.query.a...

Read more...

Revision history for this message
Théo Chamley (theo-chamley) wrote :
Revision history for this message
Théo Chamley (theo-chamley) wrote :
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

In general external types with JPA annotations need to have also the external Q-types provided. They are not generated.

Revision history for this message
Théo Chamley (theo-chamley) wrote :

That explains why it would not have worked with our framework, thanks.
But the problem remains: in the last two test cases, the Q* classes are provided in the external jar and we still get those NPE.

Thanks for your feedback.

--

Théo Chamley

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I am working on a fix.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Your example projects work now with SVN trunk. The version is 2.2.0.BUILD-SNAPSHOT.

Revision history for this message
Théo Chamley (theo-chamley) wrote :

Our project now works fine with QueryDSL.
Even if it did not impact us, the building of querydsl-mongodb failed: there are errors in GeoSpatialQueryTest and in JDKLoggerFactory.
You can close the ticket.

Thank you again,

--

Théo Chamley

Changed in querydsl:
status: In Progress → Fix Committed
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Released in 2.2.1

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.