Lombok @Builder and JPA Default constructor

前端 未结 8 1897
遇见更好的自我
遇见更好的自我 2020-12-04 11:03

I\'m using project Lombok together with Spring Data JPA. Is there any way to connect Lombok @Builder with JPA default constructor?

Code:



        
8条回答
  •  清歌不尽
    2020-12-04 11:22

    Using @NoArgsConstructor and @AllArgsContructor will help solve the issue of having a default constructor with @Builder.

    e.g

    @Entity 
    @Builder
    @NoArgsConstructor
    @AllArgsContructor
    class Person {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
    }
    

    This is because @Builder requires all argument constructor and specifying only a default constructor will cause an issue.

    Here is nore explaination: https://github.com/rzwitserloot/lombok/issues/1389#issuecomment-369404719

提交回复
热议问题