It is not possible to apply query extensions to primitive types

Bug #666723 reported by Luis Fernando Planella Gonzalez
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Medium
Timo Westkämper

Bug Description

Actually, I don't know if this is specific to JPA APT or APT in general.
Normally, for entity attributes which are boolean, I prefer to use the primitive type.
However, I tried to apply a query extension on it. My first attempt was to use:

    @QueryDelegate(Boolean.class)
    public static Predicate isFalse(BooleanPath path) {
        return path.isNotNull().or(path.eq(false));
    }

    @QueryDelegate(Boolean.class)
    public static Predicate isTrue(BooleanPath path) {
        return path.eq(true);
    }

However, using those didn't cause the primitive boolean paths to be extended. Then I replaced Boolean.class with boolean.class (the primitive), and the annotation processor throws an error. Here are the last lines:
  java.lang.IllegalArgumentException: Unsupported type kind BOOLEAN
  at com.mysema.query.apt.APTTypeFactory.getSupertypes(APTTypeFactory.java:355)
  at com.mysema.query.apt.APTTypeFactory.createEntityType(APTTypeFactory.java:229)
  at com.mysema.query.apt.Processor.processDelegateMethods(Processor.java:329)
  at com.mysema.query.apt.Processor.process(Processor.java:144)
  at com.mysema.query.apt.jpa.JPAAnnotationProcessor.process(JPAAnnotationProcessor.java:47)

My suggestion would be that the extensions should be applied over wrapper types (Integer, Boolean...) and also be applied to the respective primitive types. Would this be possible?

Changed in querydsl:
importance: Undecided → Medium
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Thanks for the bug report. I commited a fix to SVN trunk. Could you verify that the solution works for you?

Changed in querydsl:
status: New → In Progress
assignee: nobody → Timo Westkämper (timo-westkamper)
Revision history for this message
Luis Fernando Planella Gonzalez (luisfpg) wrote :

Yes, it did work. Thanks!
However, the annotation processor still crashes if trying to use a primitive type...
Maybe handling primitives just like wrapper classes would be nice too.
This is not a requirement for me, as I'll just use the wrapper class, but people using the primitive will just see the annotation processor crash...

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

This one crashes?

    @QueryDelegate(boolean.class)
    public static Predicate isFalse(BooleanPath path) {
        return path.isNotNull().or(path.eq(false));
    }

    @QueryDelegate(boolean.class)
    public static Predicate isTrue(BooleanPath path) {
        return path.eq(true);
    }

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

And is the Exception still the same?

Revision history for this message
Luis Fernando Planella Gonzalez (luisfpg) wrote :

Sorry, my bad...
For some reason, I must had something misconfigured when I tried with primitives again and got the crash....
In fact, it's working perfectly both for primitives and wrapper classes.
Thanks again!

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

Released in 2.0.3

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.