What are the ways to avoid LazyInitializationException ?
Questions
Search
List By Company
List By Topic
Legacy
Tests
Repository
DashBoard
Java
Java 8
Java 7
Java Abbreviations
OCJP / SCJP
Class List
New in Java 8
Java Exceptions
Spring Exceptions
Java Enums
Java 8 Lambda
Java 8 java.time
Big Data
Best Of Java
Discussion
Search
Subscribe
Search Interview Questions
More than 3000 questions in repository.
There are more than 900 unanswered questions.
Click here
and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company
Label / Company / Text
Search
Submit Question
Interview Questions and Answers
Q1.
What are the ways to avoid LazyInitializationException ?
Hibernate
Ans. 1. Set lazy=false in the hibernate config file.
2. Set @Basic(fetch=FetchType.EAGER) at the mapping.
3. Make sure that we are accessing the dependent objects before closing the session.
4. Force initialization using Hibernate.initialize
5. Using Fetch Join in HQL.
Help us improve. Please let us know the company, where you were asked this question
:
Like
Discuss
Correct / Improve
 hibernate   lazy loading hibernate   lazy initialization hibernate   lazyinitializationexception   architecture
Asked in 2 Companies
Correction
Duplicate of Another Question
Company where this question was Asked
Suggestion
Try 2 Question(s) Test
Which of the following is not an advantage of JSON over XML ?
Lighter and Faster
Object Representation
Supports multiple data types
Backward compatible with all XML applications
Which of following is not the resolution for preventing LazyInitializationException?
Set fetch=FetchType.EAGER for Dependent entity mapping
Make sure that we are accessing the dependent objects before closing the session
Make sure that we are accessing the dependent objects after closing the session
Wrap the complete access within Transaction
Related Questions
What is Lazy Initialization in Hibernate ?
How to do Eager loading in Hibernate ?
After which Hibernate version , related Entities are initialized lazily ?
Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?
a. Serialization
b. Runtime Polymorphism
c. Lazy Loading
d. Memory
What are the points to be considered if we move from Eager initialization to Lazy Initialization in Hibernate ?
How does Lazy Initialization helps improving performance of an application ?
What does the following exception means
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
If you are given choice to avoid LazyInitializationException using any of the following measures, which are the ones you will choose and why ?
1. Set lazy=false in the hibernate config file.
2. Set @Basic(fetch=FetchType.EAGER) at the mapping.
3. Make sure that we are accessing the dependent objects before closing the session.
4. Force initialization using Hibernate.initialize
Is it advisable to keep session or transaction open for long time just to avoid LazyInitializationException ?
Help us and Others Improve. Please let us know the questions asked in any of your previous interview.
Any input from you will be highly appreciated and It will unlock the application for 10 more requests.
Company Name:
Questions Asked: