Skip to content

OneToMany does not support initialisation via List.of() - Was - Fetching multiple ToMany eagerly doesn't work on transitive associations #3573

@apflieger

Description

@apflieger

Underlying issue here:

@OneToMany
private List<Attendance> attendances = List.of(); // we can't use List.of() 

A collection initialised with List.of() isn't supported. It should be left uninitialised or initialised as new ArrayList<>() [which are treated exactly the same, ebean enhancement removes that initialisation code as it must control the initialisation of collections to support orphanRemoval and ManyToMany adds/removes]


Hi,

Thanks a lot for your work, that's always worth saying.

Context

I am trying to load an entity that has multiple ToMany relations, but transitively, in a single EBean query. The model look like this:

class Payment {
    @ManyToOne
    Ticket ticket;
}

class Ticket {
    @OneToMany
   List<Payment> payments;

    @OneToMany
   List<Attendance> attendances;
}

I am fetching Payments entities with a FetchGroup that queries the two paths ticket.payments and ticket.attendances.

Expected behavior

I expect to have one query with a join for the first relation, and a secondary query for the second.

Actual behavior

What I see is that secondary queries are not executed, everything is then lazy loaded one row at a time.

I didn't setup a reproduction case, let me know if that's necessary. But I spent some time to debug and I landed here
At this point we are in a secondary query, but it got skipped by the condition loadBuffer.size() > 0, this buffer is empty at this stage. I couldn't understand why exactly. What I found is that this buffer is created based on Bean descriptions in this code (ctx.register calls DLoadManyContext.createBuffer), but the bean description of the query (root entity Payment) doesn't contain many assoc, so localDesc.propsMany() is empty on line 303

Additional note

I can't affirm it's a regression because we changed our model and queries, but I feel like this worked in the past.

Cheerz and long live EBean ✌️

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions