I have a database with a quite large entity model. In total, there are 14 tables with around 100k records on average.
When I tested my application that takes one entity from the database and converts it to json and throws that back to the caller, it took 7 seconds to get the entry.
This doesnt seem an initialization issue because if I do the same call twice in a row, they both take around 10 seconds to get the data.
When I enable sql script logging, I find that for each entity read, hibernate sends hundreds of sql requests to the database. (The actual number is based on how many connections/licenses/products/services etc the entity has but for my test entry, I got 286 queries (which took around 7 seconds in total)) When the database is empty (except for the data that the test should return), then it takes around 6 seconds.
I suppose the issue is because I have my @OneToMany's and @ManyToMany's fetch set to Lazy, but when I set them to eager, I get the error of multiple fetch bags.
@javax.persistence.OneToMany(fetch = javax.persistence.FetchType.LAZY)
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.FALSE)
@javax.persistence.JoinColumn(name = "ProductId")
This is an example of a OneToMany relation I have, which simulates the eager fetch without the multiple fetch bags error.
Is this a common issue? And how do I improve the speed on the reading?