dbperftest.zip (242.3 KB)
It took me some time to figure out, why my browse view is so slow. After turning on eclipselink SQL output it was immediately apparent that there are way too many read queries created.
I finally reproduced it in a sample project by pre-instantiating fields with List type. E.g. the designer creates this:
@JoinTable(name = "COMPANY_COST_UNIT_LINK",
joinColumns = @JoinColumn(name = "COMPANY_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "COST_UNIT_ID", referencedColumnName = "ID"))
@ManyToMany
private List<CostUnit> relatedCostUnits;
And I added the new ArrayList<>()
:
@JoinTable(name = "COMPANY_COST_UNIT_LINK",
joinColumns = @JoinColumn(name = "COMPANY_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "COST_UNIT_ID", referencedColumnName = "ID"))
@ManyToMany
private List<CostUnit> relatedCostUnits = new ArrayList<>();
So you say “just keep it like the designer created it” - well, in my real project I’m using kotlin actually and with kotlin the following is created by designer and therefore you also run into the issue with the unnecessary read queries: (a lot of them)
The solution (for now) is to change these lines to something like:
var relations: MutableList<...>? = null