Skip to content
Advertisement

(N + 1) selects problem with child Map-collection

friends! I have these entities:

Document:

and ChangeNotice:

And these are my repositories:

For Document:

and for ChangeNotice:

So, when i want to get Document with changeNotices, thats not a problem, i have only one select. But when i want to get ChangeNotice with documents – i have (n + 1), first for document, and n for changeNotices Map.

I use join fetch in my query, but it does not help. I think the problem is that in Document i have Map<K,V>, where entity is a value, and i should use @ManyToMany relationship. And in ChangeNotice i have Map<K,V>, where entity is a key, and i should use @ElementCollection.

Are there any ways to write a query that select ChangeNotice with documents in one select? (without changing my entities code, may be small fixes possible)

Advertisement

Answer

So, a lot of time has passed, i didn’t find an answer. But it is my architecture issue. I had to use another class, that contains Document, ChangeNotice, and Integer field. My Document and ChangeNotice entities had child collection of this class with @OnetoMany relationship. It solves the problem.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement