Feature requests for logging inefficient ops: (N+1)^X relation and large collection load

Hello! There’s a couple features my company could really use for identifying excessive db round trips.

  • Large entity collection load warning. We have some in-house code I may be able to contribute for this. A logging option to enable a warning when large collections are loaded via 1:m and m:m relations like parent.getChildren() . A stack trace is desired for this warning to help users track down which collection was too large. Also include entity name and PK if present. We use an integration with HIbernate SPI to warn when over 500 child entities are loaded. We have experienced several Out Of Memory crashes due to programmers not paying attention to cardinality in these relations, especially the m:m flavor.
  • Related, a log warning option for detecting nested N+1 queries. Like parent.getChildren().stream().flatMap(child->child.getGrandchildren().stream()). I haven’t figured out a good way to do this, but basically, detect when multiple levels of 1:M and M:M relations are loaded on an entity graph within the same Session. This is also something our developers struggle with, as its easy to accidentally load multiple levels of child entities using Java8 Streams.

I may be able to get company time to help if community and core devs are interested