I have the following JPA entity
@Data
@Builder
public class Post {
@Id
@GeneratedValue
UUID id;
@OneToMany
Set<PostTags> tags;
String content;
}
@Data
public class PostTag {
@Id
@GeneratedValue
UUID id;
@OneToOne
Post post;
String tag;
}
Using lombok @Builder I want to be able to do the following
Post post = Post.builder()
.tags("hello", "world")
.content("Hello world")
.build();
I am presuming I need a custom builder along the lines of
public static class PostBuilder {
private Set<String> myTags = new HashSet<>();
public PostBuilder tags(String... tags) {
myTags.addAll(Arrays.asList(tags));
return this;
}
}
From the documentation it appears there ObtainVia annotation that I can use, but I am not sure how to get around it (no example on the doc) and especially since I only want myTags to be a builder specific thing, and not be exposed on the main class itself.