
JPA fetch control that doesn't suck
I got tired of JPA fetch control being broken for 20 years, so I built something. Fetch control in JPA has always been a mess. Eager loading kills performance the moment your object graph gets non-trivial. Lazy loading hands you N+1 problems and LazyInitializationException as a reward for doing the right thing. Most serious projects I've seen land in one of two places: lazy + proliferation of nearly-identical queries that differ only in what they fetch, or they give up on mapping relationships altogether and treat their relational DB like a document DB. The others either have these performance issues, or don't yet know that they have them. The named query proliferation problem Here's what that proliferation looks like in practice. You start with a simple named query: @NamedQuery ( name = "Person.findByName" , query = "select p from Person p where p.name = ?1" ) @NamedQuery ( name = "Person.findByNameWithOrganization" , query = "select p from Person p join fetch p.organization where p.n
Continue reading on Dev.to
Opens in a new tab




