No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor

后端 未结 8 1785
野的像风
野的像风 2020-12-04 15:15

When i try to navigat to an endpoint i get tho following error

Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddy

相关标签:
8条回答
  • 2020-12-04 15:57

    I also faced with this problem. @Szelek's answer helped me. But I did it with another way. Changed getOne() method to:

    repository.findById(id).orElse(null)
    
    0 讨论(0)
  • 2020-12-04 15:58

    You can Ignore to produce JSON output of a property by

    @JsonIgnore 
    

    Or If you have any lazy loaded properties having a relationship. You can use this annotation at top of the property.

    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) 
    

    Example:

    @Entity
    public class Product implements Serializable{
       private int id;
       private String name;
       private String photo;
       private double price;
       private int quantity;
       private Double rating;
       private Provider provider;
       private String description;
    
       @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
       private List<Category> categories = new ArrayList<>();
    
       @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
       private List<Photo> photos = new ArrayList<>();
    
       // Getters & Setters
    }
    

    If you still have this error, please add this line of code in your application.properties file

    spring.jackson.serialization.fail-on-empty-beans=false
    

    I hope your problem will be solved. Thanks.

    0 讨论(0)
  • 2020-12-04 15:58

    i also faced same problem. I was using repo.getOne(id); i changed it to repo.findById(id). It returned optional, but now error is gone

    0 讨论(0)
  • 2020-12-04 16:05

    Changing the FetchType from lazy to eager did the trick for me.

    0 讨论(0)
  • 2020-12-04 16:09

    I came across this error while doing a tutorial with spring repository. It turned out that the error was made at the stage of building the service class for my entity.

    In your serviceImpl class, you probably have something like:

        @Override
        public YourEntityClass findYourEntityClassById(Long id) {
          return YourEntityClassRepositorie.getOne(id);
        }
    

    Change this to:

        @Override
        public YourEntityClass findYourEntityClassById(Long id) {
          return YourEntityClassRepositorie.findById(id).get();
        }
    

    It's because the getOne(), returns a reference.

    0 讨论(0)
  • 2020-12-04 16:09

    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) work for me very well. It doesn't miss any reference objects and resolve the problem.

    In my case:

    @Entity
    @Table(name = "applications")
    public class Application implements Serializable {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
    
        @NotBlank
        @Size(max = 36, min = 36)
        private String guid;
    
        @NotBlank
        @Size(max = 60)
        private String name;
    
        @Column(name = "refresh_delay")
        private int refreshDelay;
    
        @ManyToOne(fetch = LAZY)
        @JoinColumn(name = "id_production", referencedColumnName = "id")
        @JsonIgnoreProperties(value = {"applications", "hibernateLazyInitializer"})
        private Production production;
    
    0 讨论(0)
提交回复
热议问题