Support defining lazy attribute fetch groups
Description
causes
is a fix for
relates to
Activity
Show:
Steve Ebersole November 11, 2015 at 4:49 AM
Notes to self...
Many places in the code base have a concept of "lazyPropertiesAreUnfetched". The simple boolean worked previously because of the fact that there was just one fetch group. As we transition to multiple fetch groups this needs to change to become the name of all fetched fetch-groups (all unfetched groups works too, but fetched groups is better).
org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromDatastore
(as part of theorg.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer#initializeLazyProperty
call chain) needs to be re-worked to understand fetch groups. Which meansorg.hibernate.persister.entity.AbstractEntityPersister#getSQLLazySelectString
needs similar reworking
When using bytecode enhanced lazy loading, the current scheme is to fetch all lazy attributes when one is accessed. There are many times it would be great to define groupings of attributes to be fetched when one of the group is accessed.
In a sense, the current scheme is a single "fetch group". This is about adding the ability for the user to explicitly control the definition of other groups.
A single attribute could only belong to one fetch group.
The annotation to control this is
org.hibernate.annotations.LazyGroup
, e.g.:@Entity public class Customer { @Id private Integer id; private String name; @Basic( fetch = FetchType.LAZY ) private UUID accountsPayableXrefId; @Lob @Basic( fetch = FetchType.LAZY ) @LazyGroup( "lobs" ) private Blob image; ... }
Both
accountsPayableXrefId
andimage
are lazy, but each is part of a different fetch group (accountsPayableXrefId
is part of the default fetch group). Which means that accessingaccountsPayableXrefId
will not force the loading ofimage
.By default all lazy singular attributes are part of a group named "DEFAULT" and all plural attributes are their own group.
For many-to-one and one-to-one attributes, it is expected that they also be marked with
@LazyToOne(LazyToOneOption.NO_PROXY)
, for now. The reason is legacy. We are discussing relaxing that requirement since I believe bytecode-enhancement + lazy to-ones always want NO_PROXY there.