JPA查询报错:No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer...

错误信息:

2019-01-10 17:02:30.701  WARN 18088 --- [nio-9000-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.xadhsd.book.server.entity.UnscrambleBook["book"]->com.xadhsd.book.server.entity.Book_$$_jvst8fb_26["handler"])

解决办法:

修改注解文件多对多的配置,如下所示:

1、图书表的配置:

@ManyToOne
    @JoinColumn(name = "book_id")

    public Book getBook() {
        return this.book;
    }
 

2、推荐图书表(中间表)的配置:

@JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "book", orphanRemoval = true)
    public Set<RefereeBook> getRefereeBooks() {
        return this.refereeBooks;
    }

    public void setRefereeBooks(Set<RefereeBook> refereeBooks) {
        this.refereeBooks = refereeBooks;
    }

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页