org.hibernate.LazyInitializationException at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel

后端 未结 2 634
情歌与酒
情歌与酒 2020-12-01 12:52

Despite of FetchType.EAGER and JOIN FETCH, I get a LazyInitalizationException while adding some objects to a @ManyToMany

2条回答
  •  天涯浪人
    2020-12-01 13:31

    Solution: Replace the editUserBehavior.currentUser.employers with collection that is not managed by Hibernate.

    Why? When the Entity becomes managed, the Hibernate replaces your HashSet with its own implementation of Set (be it PersistentSet). By analysing the implementation of JSF MenuRenderer, it turns out that at one point it creates new Set reflectively. See the comment in MenuRenderer.convertSelectManyValuesForModel()

    // try to reflect a no-argument constructor and invoke if available

    During construction of PersistentSet initialize() is invoked and - as this class is only meant to be invoked from Hibernate - LazyInitializationException is thrown.

    Note: This is my suspicion only. I don't know your versions of JSF and Hibernate but this is more likely the case.

提交回复
热议问题