Could not write content: failed to lazily initialize a collection of role

后端 未结 9 1320
说谎
说谎 2021-02-08 02:48

I have One-To-Many relationship, here is my code

@Entity
@Table(name = \"catalog\")
public class Catalog {

    @Id
    @GeneratedValue(strategy = GenerationType         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 03:34

    A third option which can be useful if you don't want to use EAGER mode and load up everything is to use Hibernate::initialize and only load what you need.

    Session session = sessionFactory.openSession();
    Catalog catalog = (Catalog) session.load(Catalog.class, catalogId);
    Hibernate.initialize(shelf);
    

    More information

提交回复
热议问题