InterviewSolution
Saved Bookmarks
| 1. |
What is Hibernate Validator Framework? |
|
Answer» The LazyInitializationException is THROWN when TRYING to access a relationship with another entity which is not initialized and without an ACTIVE session. The below simple code snippet explains this reason. Example.java EntityManagerem = emf.createEntityManager(); em.getTransaction().begin(); Author a = em.find(Author.class, 1L); em.getTransaction().commit(); em.close(); logger.info(a.getFirstName() + " "+ a.getLastName() + " WROTE "+a.getBooks().SIZE() + " books.");The best way to fix a LazyInitializationException is to initialize the required relationship in the business tier. It is also not advisable to initialize all relationships just because there might be one client out there who needs one of them. For performance reasons, you should only initialize the relationships you need. |
|