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

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

    Using FetchType.LAZY , if still getting the error "Could not write content: failed to lazily initialize a collection of role" , that may be probably caused by somewhere in the logic (perhaps in a controller) , Catalog is being tried to be deserialized that contains list of catalog items which is a proxy but the transaction has already ended to get that. So create a new model ('CatalogResource' similar to catalog but without the list of items). Then create a catalogResource object out of the Catalog (which is returned from the query)

    public class CatalogResource {
        private int catalog_id;
        private String name;
        private List orders;
    } 

提交回复
热议问题