Home > Mobile >  http.converter.HttpMessageConversionException: Type definition error: [simple type class org.hiberna
http.converter.HttpMessageConversionException: Type definition error: [simple type class org.hiberna

Time:07-25

I checked all my models and all the attributes have getters and setters.

I can fix that by adding spring.jackson.serialization.fail-on-empty-beans=false but i think this is just a work around to hide the exception.So what's is the issue here?

Exception in :org.springframework.http.converter.HttpMessageConversionException: 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 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;
    
    }

CodePudding user response:

Try below code

@JsonBackReference @OneToMany(mappedBy = "comment", fetch = FetchType.EAGER ,cascade = CascadeType.ALL) @JsonIgnoreProperties("comment") protected List mentions = new ArrayList<>();

CodePudding user response:

As mentioned in my comment, FetchType.EAGER on Employee user in CommentMention should do the trick because when you are serializing the response, the user is lazily initialized, so you would need to fetch it before serializing.

Check these links for more information:

Difference between FetchType LAZY and EAGER in Java Persistence API?

https://www.baeldung.com/hibernate-lazy-eager-loading

  • Related