Generation of Query classes within a type hierarchy becomes inconsistent when using @Column annotation

Bug #841568 reported by Torben Knerr
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Undecided
Unassigned

Bug Description

Consider the following type hierarchy:
- A2 extends A
- B2 extends B

A has a reference to B, and for the more specific classes A2 has a reference to B2. See the example code below.

Now the problem is: as soon as we use the @Column annotation in A2, the generation of the Query classes becomes inconsistent, i.e. QA2.a2.b() is no longer of type B2 but of type B instead, which breaks the ability of formulating polymorphic queries in this case.

Test Case below (just uncomment the @Column annotation and you will get a compile error in main()):

<code>
package test;

import javax.persistence.Entity;

public class Test {
 public static void main(String[] args) {
  QB2 qb2 = QA2.a2.b();
 }
}

@Entity
class A {

 B b;

 A(B b) {
  this.b = b;
 }

 B getB() {
  return b;
 }
}

@Entity
class A2 extends A {

 // XXX: uncomment @Comment to break generation - QA2.a2.b() will then return B instead of B2
 // @Column
 int foo;

 A2(B2 b2) {
  super(b2);
 }

 @Override
 B2 getB() {
  return (B2) super.getB();
 }
}

@Entity
class B {
}

@Entity
class B2 extends B {
}

</code>

Revision history for this message
Lars Neumann (lars.neumann) wrote :

This behaviour exists in 2.2.1 and 2.2.0.beta5. Is there a quick work-around?

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

Querydsl APT decides on a class by class basis if fields, properties or both are taken into account for meta model generation.

When no processable annotations are presented, like when the @Column annotation is commented out, both fields and properties are tracked, when @Column is available, only fields are tracked.

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

I made some small modifications to Querydsl APT and now you can solve the problem like this :

    @Entity
    class A2 extends A {

        // return B instead of B2
        @Column
        int foo;

        A2(B2 b2) {
            super(b2);
        }

        @Override
        @QueryType(PropertyType.ENTITY)
        B2 getB() {
            return (B2) super.getB();
        }
    }

In this case both field and getter annotations are taken into account.

Changed in querydsl:
status: New → Fix Committed
Revision history for this message
Lars Neumann (lars.neumann) wrote :

Cool, thanks! We'll try that.

Would it be possible for you to release a beta when https://bugs.launchpad.net/querydsl/+bug/841795 has also been fixed? This would allow us to finally upgrade from 2.2.0.beta5

Cheers

Revision history for this message
Torben Knerr (torben-knerr) wrote :

Thanks a lot!

Interested to get your feedback about https://bugs.launchpad.net/querydsl/+bug/841795 as well :-)

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

Released in 2.2.2

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.