Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| |||||||||||
Hibernate - Interview Questions and Answers for 'Lazyinitializationexception' - 4 question(s) found - Order By Newest | |||||||||||
| |||||||||||
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. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() ![]() | |||||||||||
![]() | |||||||||||
| |||||||||||
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() | |||||||||||
| |||||||||||
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping. third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished. I don't mind using 4th too. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() | |||||||||||
| |||||||||||
Ans. No. It's a resource and performance overhead. | |||||||||||
![]() | |||||||||||
![]() ![]() ![]() | |||||||||||
| |||||||||||