failed to lazily initialize a collection of role

前端 未结 4 830
盖世英雄少女心
盖世英雄少女心 2020-12-12 20:49

Hi I have two classes like this:

public class Indicator implements Serializable {
...

    @OneToMany(mappedBy = \"indicator\",fetch=FetchType.LAZY)
    priv         


        
4条回答
  •  半阙折子戏
    2020-12-12 21:42

    Lazy exceptions occur when you fetch an object typically containing a collection which is lazily loaded, and try to access that collection.

    You can avoid this problem by

    • accessing the lazy collection within a transaction.
    • Initalizing the collection using Hibernate.initialize(obj);
    • Fetch the collection in another transaction
    • Use Fetch profiles to select lazy/non-lazy fetching runtime
    • Set fetch to non-lazy (which is generally not recommended)

    Further I would recommend looking at the related links to your right where this question has been answered many times before. Also see Hibernate lazy-load application design.

提交回复
热议问题