6

I'm using lombok project with Entity here is my example :

package com.company.entities;//<---------Note the package 

import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.Builder; 
import lombok.Getter; 
import lombok.Setter;

@Entity
@Builder
@Getter @Setter @AllArgsConstructor @NoArgsConstructor @ToString
public class Client {

    @Id
    private long id;
    private String firstName;
    private String lastName;

}

So when I try to use in the same package, It works fine :

When I change the package for example to package com.company.controllers; :

package com.company.controllers;//<---------Note the package 

public class Mcve {

    public static void main(String[] args) {
        Client client = new Client.ClientBuilder()
                .id(123)
                .firstName("firstName")
                .lastName("lastName")
                .build();
    }     
}

I get an error :

ClientBuilder() is not public in com.company.entities.Client.ClientBuilder; cannot be accessed from outside package

I tried all the solution in this posts :

I test with lombok 1.16.18 and 1.16.20.

When I create my own builder class it works fine, but when I use @Builder it not, I know what does this mean, but no way, I can't arrive to solve this issue ! what should I do to solve this problem?

YCF_L
  • 51,266
  • 13
  • 85
  • 129

1 Answers1

19

You don't have to instantiate the builder. Instead use:

  Client client = Client.builder()
            .id(123)
            .firstName("firstName")
            .lastName("lastName")
            .build();
YCF_L
  • 51,266
  • 13
  • 85
  • 129
Simon Martinelli
  • 27,740
  • 3
  • 37
  • 65