0

I set lazy property as "true" in my hbm mapping file. However I want to change "lazy=false" dynamically through code. how can I achieve this?

2 Answers 2

1

You can use either joins via HQL or FetchMode.JOIN via Criteria API, in this case you'll get your associations in a single shot. Note, that associated objects won't be fetched from 2nd level cache if you use it.

Another option is Hibernate.initialize() or simply just invoke object.getAssociation().

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

Comments

0

Look at sessionFactory.getClassMetadata(YourClass.class). It has the methods to access every field.

The more civilized way, however, is to override fetching strategy with HQL or Criteria query. Another option is to modify your metadata (having lazy="false") and rebuild the session factory. It's not that scary as it looks like.

Comments

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.