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

Bug #841568 reported by Torben Knerr on 2011-09-05
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>

Lars Neumann (lars.neumann) wrote :

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

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.

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
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

Torben Knerr (torben-knerr) wrote :

Thanks a lot!

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

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  Edit
Everyone can see this information.

Other bug subscribers