Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q classes not generated properly for oneToMany relationships #675

Closed
damienhollis opened this issue Mar 10, 2014 · 5 comments
Closed

Q classes not generated properly for oneToMany relationships #675

damienhollis opened this issue Mar 10, 2014 · 5 comments
Labels
bug
Milestone

Comments

@damienhollis
Copy link

@damienhollis damienhollis commented Mar 10, 2014

Hi Timo,

Thanks for the fix you did in #82. I've now found a similar problem with oneToMany relationships, e.g. we have an order that has order items.

The order is implemented as an interface Order and implementation OrderImpl.
The order item is implemented as an interface OrderItem and implementation OrderItemImpl.

The JPA annotations on the relationship look like this:

@OneToMany(targetEntity = OrderItemImpl.class, fetch = LAZY, mappedBy = "order", cascade = ALL)
private List<OrderItem> orderItems;

However, the Q class generated for the OrderImpl (QOrderImpl) has this for the relationship:

public final ListPath<OrderItem, SimplePath<OrderItem>> orderItems = this.<OrderItem, SimplePath<OrderItem>>createList("orderItems", OrderItem.class, SimplePath.class, PathInits.DIRECT2);

Which I can't use in queries because I need a QOrderItemImpl.

Hope this makes sense - refer to issue 82 for clarification. Can you do a similar fix for collections?

Thanks,
Damien

@timowest timowest added the bug label Mar 10, 2014
timowest added a commit that referenced this issue Mar 13, 2014
@timowest timowest added the fixed label Mar 13, 2014
@timowest
Copy link
Member

@timowest timowest commented Mar 24, 2014

Released in 3.3.2

@timowest timowest closed this Mar 24, 2014
@damienhollis
Copy link
Author

@damienhollis damienhollis commented Mar 24, 2014

Hi Timo,

Thanks for making this change. Unfortunately it does not seem to handle Maps correctly, for example I have a map annotated as follows:

    @OneToMany(targetEntity = ManagedEmailImpl.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true, mappedBy = "emailManager")
    @MapKey(name = "emailType")
    private Map<EmailType, ManagedEmail> emails;

And I get the following error when trying to generate q classes:

[javac] java.lang.IllegalArgumentException: Incorrect number of type arguments
[javac]     at com.sun.tools.javac.model.JavacTypes.getDeclaredType0(JavacTypes.java:245)
[javac]     at com.sun.tools.javac.model.JavacTypes.getDeclaredType(JavacTypes.java:221)
[javac]     at com.mysema.query.apt.jpa.JPAConfiguration.getRealElementType(JPAConfiguration.java:141)
[javac]     at com.mysema.query.apt.jpa.JPAConfiguration.getRealType(JPAConfiguration.java:126)
[javac]     at com.mysema.query.apt.TypeElementHandler.handleEntityType(TypeElementHandler.java:97)
[javac]     at com.mysema.query.apt.AbstractQuerydslProcessor.processAnnotations(AbstractQuerydslProcessor.java:150)
[javac]     at com.mysema.query.apt.AbstractQuerydslProcessor.process(AbstractQuerydslProcessor.java:122)
[javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
[javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
[javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
[javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
[javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
[javac]     at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
[javac]     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
[javac]     at com.sun.tools.javac.main.Main.compile(Main.java:439)
[javac]     at com.sun.tools.javac.main.Main.compile(Main.java:353)
[javac]     at com.sun.tools.javac.main.Main.compile(Main.java:342)
[javac]     at com.sun.tools.javac.main.Main.compile(Main.java:333)
[javac]     at com.sun.tools.javac.Main.compile(Main.java:76)
[javac]     at com.sun.tools.javac.Main.main(Main.java:61)

Note: that the @mapkey annotation is used to specify the field on the targetEntity to use as the key of the map. And it could also be an entity. An example of such a case (this code is not complete) would be:

@Entity
public class WorkgroupImpl implements Workgroup {

    @OneToMany(targetEntity = WorkgroupMemberImpl.class, mappedBy = "workgroup", orphanRemoval = true)
    @Cascade(ALL)
    @MapKey(name = "user")
    private Map<User, WorkgroupMember> members;
 }

@Entity
public class WorkgroupMemberImpl implements WorkgroupMember {

    @ManyToOne(targetEntity = WorkgroupImpl.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "WORKGROUP_ID")
    private Workgroup workgroup;

    @ManyToOne(targetEntity = UserImpl.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ID")
    private User user;

}

I can test any fixes you provide.

Regards,
Damien

timowest added a commit that referenced this issue Mar 25, 2014
@timowest
Copy link
Member

@timowest timowest commented Mar 25, 2014

Thanks for testing. Could you try again with the latest SNAPSHOT from https://oss.sonatype.org/content/repositories/snapshots/

@timowest timowest reopened this Mar 25, 2014
@timowest timowest removed the fixed label Mar 25, 2014
@damienhollis
Copy link
Author

@damienhollis damienhollis commented Mar 25, 2014

Hi Timo,

That seems to have fixed the code generation. I haven't had a chance to test whether the generated code works as expected yet but I will open another ticket if there are any other problems.

Also, I don't think your code deals with @manytomany relationships - this isn't a problem for me yet but will be sometime soon.

Thanks again for fixing this so quickly.

Cheers,
Damien

@timowest timowest added the fixed label Mar 25, 2014
@timowest timowest modified the milestones: 3.3.2, 3.3.3 Apr 13, 2014
@timowest timowest modified the milestone: 3.3.3 Apr 30, 2014
@timowest
Copy link
Member

@timowest timowest commented May 2, 2014

Released in 3.3.3

@timowest timowest closed this May 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.