LazyInitializationException when adding to a list that is held within a entity class using hibernate and gilead for gwt

余生长醉 提交于 2019-12-02 02:49:04
Bozho

Lazy means that the values of the collection are loaded from the database only when they are accessed. If at that time the Session has been closed, the LazyInitializationException is thrown, because the data cannot be fetched.

In your case I'd simply suggest adding an eager fetch type to the association:

@ManyToMany(cascade = CascadeType.ALL, fetchType=FetchType.EAGER)

This will load the fileLocations when the entity is loaded and no lazy loading will be needed.

A common solution is to use OpenSessionInView, but it may not always work with GWT, becaucse the client is remote and the session cannot be opened there.

So you are going to have some problems with lazy initialization. You can search around for related questions, there are a few - this and this for example.

This exception means that the FileLocations association is not yet loaded and you are trying to access it. There is no session opened, and there is no way to load the association. This is the LazyInitializationException.

Edit: Read Bozho's post for the solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!