I currently have Repository entity (lazy) in hibernate. When the controller is called, I want to open a session and load Repository before accessing repo.getIbId() because currently it throws LazyInitializationException. In my RepositoryDao class, I would like to load them before accessing ibid. Here are my couple approaches:
Use Hibernate.initialize(Repository.class) in the service layer. To be honest, I am not sure how this because I read I need to have open session in order to do this.
In my Dao layer, I can do
sessionFactory.getCurrentSession()to open a session and then do something in here such assessionFactory.getCurrentSession().get(Repository.class, ???)but not sure what to do here. Can I just do select * from Repository to load this entity?
Is there better way to handle this?
repo.getIbId()this specific to your entity ? Throws a LazyInitializationException, so try to solve this. Why want you to circumvent Hibernate ?LazyInitializationExceptionis caused by repo.getIbId() because Repository entity has not been loaded.