Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :

  • Lombok @Builder and JPA Default constructor
  • Using lomboks @Data and @Builder on entity

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?

like image 994
YCF_L Avatar asked Jan 18 '18 18:01

YCF_L


1 Answers

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

  Client client = Client.builder()
            .id(123)
            .firstName("firstName")
            .lastName("lastName")
            .build();
like image 148
Simon Martinelli Avatar answered Oct 11 '22 13:10

Simon Martinelli