1

When setting Lazy=false, then hibernate will automatically loads the objects into the required sets e.g.

<set name="Options" table="ATTRIBUTEOPTION" inverse="false"  cascade="all" lazy="false">
        <key>
            <column name="ATTRIBUTEID" />
        </key>
        <one-to-many class="com.BiddingSystem.Models.AttributeOption" />
</set>

but if in my xml mapping, I place lazy=true and in some place in my application i decide that i want to load all attribute options, should i do it manually, or is there a technique which lets tells hibernate that now i want to set lazy=false??

2 Answers 2

4

You can't change the configuration at runtime. But you can use Hiberante.initialize(..) to initialize lazy collections.

Sign up to request clarification or add additional context in comments.

Comments

3

Yo can do it manually simply using getOptions(). But if when loading the entity you already now that you will need the options then you can do an eager fetch using fetch join this way:

 select c from EntityX c left join fetch c.Options

And it's an important optimitzation beacuse you can avoid a lot of extra selects if you prefetch data that you will know that will be needed.

1 Comment

Ya, I have included hibernate in my project, now i need to get down to optimization!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.