我检查了我所有的模型,所有的属性都有getter和setter。
我可以通过添加spring.Jackson.serialization.fail-on-empty-beans =false来修复这个问题,但我认为这只是一个隐藏异常的解决方案。
在以下位置发生异常:类型定义错误:[简单类型,类组织。休眠。代理。pojo。Java辅助。Java辅助惰性初始化程序];嵌套的异常是com.fasterxml.Jackson.数据绑定.exc。无效定义异常:未找到类org. hib.proxy.pojo.javassist.JavassistLazyInitializer的序列化程序,也未发现用于创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:[0]-〉com.auzmor. platform. models. entities.雇员_$$_jvst80f_13 [“处理程序”])
Error request : ServletWebRequest: uri=/api/v1/notes;client=0:0:0:0:0:0:0:1;user=com.auzmor.platform.configurations.auth.CustomPrincipal@3d7c4c43
Error Message : Type definition error: [simple type, class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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: java.util.ArrayList[0]->com.auzmor.platform.models.results.notes.NoteResult["mentions"]->java.util.ArrayList[0]->com.auzmor.platform.models.entities.Employee_$$_jvst80f_13["handler"])
Error Cause : com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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: java.util.ArrayList[0]->com.auzmor.platform.models.results.notes.NoteResult["mentions"]->java.util.ArrayList[0]->com.auzmor.platform.models.entities.Employee_$$_jvst80f_13["handler"])
3.CandidateComment-------------------------------------------------------------------
@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "candidate_comments")
@DynamicInsert
@javax.persistence.Entity
@DynamicUpdate
@ToString
public class CandidateComment extends Entity implements Serializable {
@ApiModelProperty(notes="Text of the note")
@Size(min = MIN_SIZE, message="text should have at least 1 characters")
@Size(max = MAX_TEXT_SIZE, message="text should not exceed 2048 characters")
private String text;
private boolean isExternalAgency;
@JsonBackReference
@OneToMany(mappedBy = "comment", fetch = FetchType.EAGER ,cascade = CascadeType.ALL)
@JsonIgnoreProperties("comment")
protected List<CommentMention> mentions;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "author_id", insertable = false, updatable = false)
@JsonIgnoreProperties({"fullName","mobile"})
protected Employee author;
@JsonIgnore
@Column(name = "author_id")
protected Long authorPK;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "candidate_id", insertable = false, updatable = false)
protected Candidate candidate;
@JsonIgnore
@Column(name = "candidate_id")
protected Long candidatePK;
}
4.CommentMention -----------------------------------------------------------
@Getter
@Setter
@AllArgsConstructor
@Table(name = "comment_mentions")
@DynamicInsert
@javax.persistence.Entity
@DynamicUpdate
@NoArgsConstructor
public class CommentMention extends BaseEntity implements Serializable {
@JsonBackReference
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "comment_id", insertable = false, updatable = false)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
protected CandidateComment comment;
@JsonIgnore
@Column(name = "comment_id")
protected Long commentPK;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", insertable = false, updatable = false)
@JsonIgnoreProperties({"fullName","mobile"})
protected Employee user;
@JsonIgnore
@Column(name = "user_id")
protected Long userPK;
}
2条答案
按热度按时间brvekthn1#
正如我在评论中提到的,在CommentMentionEmployee用户上的FetchType.EAGER应该可以解决这个问题,因为当您序列化响应时,用户是惰性初始化的,因此您需要在序列化之前获取它。
有关详细信息,请查看以下链接:
Difference between FetchType LAZY and EAGER in Java Persistence API?
https://www.baeldung.com/hibernate-lazy-eager-loading
7gcisfzg2#
请尝试以下代码