0
votes

Kinda of embarrassing to ask this question after few years working with Hibernate...

I have a master_table which :

  • have some @OneToMany(fetch=FetchType.LAZY, mappedBy="something ")
  • and some @ManyToOne(fetch=FetchType.LAZY)
  • may have some @OneToOne
  • same thing in child_table

I loaded only master_table which gave me about 500 rows. However in the background, it was about 6000 queries made. (quite sure that there is no EAGER)

Question: is that normal ? Is that possible to load this table with just 1 query without impacting lazy loading mechanism, which is working quite very-well here.

Thanks

1
Hard to say without seeing the actual configuration.Marvo

1 Answers

0
votes

The answer is quite easy: - Using Fetch = Subselect on @OneToMany gave me only one query. As it is lazy, when the children are needed, the corresponding queries will be generated - Using BatchSize is also a good option