Hibernate Lazy Download Package

I am currently observing the following behavior in hbernate3. if I had a @BatchSize (size = 5) set, then hibernate will select 5 subsets of the display type in a single SQL query.

If I have .setFetchMode ("set", FetchMode.JOIN); , then hibernate will look forward to receiving all subsets of the mapped type in a single SQL query.

However, when I install .setFetchMode ("commands", FetchMode.SELECT); then hibernate still uses batch fetching rather than lazy fetching.

Is there a way to make hibernate use lazy choice when @ Batch size is set?

The same question applies when @Fetch (FetchMode.SUBSELECT) is installed.

+4
source share
2 answers

If you want to programmatically change these parameters, you can use @FetchProfile. Just create @FetchProfile for the object:

@FetchProfiles({ @FetchProfile(name = "profileName", fetchOverrides = { @FetchProfile.FetchOverride(entity = YourEntity.class, association = "anAssociation", mode = FetchMode.JOIN), ... 
}) })
and enable that profile in your service / repository method like:

 session.enableFetchProfile( "profileName" ); 
and your customized fetch settings will work for that session.
+7
source

Sorry, but @BatchSize is used to solve the "N + 1" problem, but do not ask Hibernate for downloaded objects with impatience or lazy. Try searching for the keywords: "Hibernate, n + 1 problem, batch size."

0
source

All Articles