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

后端 未结 9 1351
说谎
说谎 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:30

    I know this is an old post but this might still help someone facing a similar issue. To solve the problem, iterate through the list of items and set the lazy-loadable collection to null. Then set your mapper to include NON-NULL

     for (Catalog c : allCatalogs) {
            c.setItems(null);
        }
    
    objectMapper.setSerializationInclusion(Include.NON_NULL)
    

提交回复
热议问题