I have Entity class annotated with lombook annotation ( https://projectlombok.org/features/all ):
@Getter
@Setter
@EqualsAndHashCode
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "members")
public class Member implements Serializable {
private final static long serialVersionUID= 1l;
@id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id", unique = true)
private Long id;
@Column(name="name")
@NonNull
private String name;
@Column(name="photo")
@NonNull
private String photo;
@Column(name="descriotion")
private String descriotion;
@Column(name="winner_in_period")
private String winnerInPeriod;
@Column(name="created_date")
private Date createdDate;
@Column(name="deleted")
private Boolean deleted;
}
And I have service which gives me data from the database using this Entity. Finally I try to get some data from Member object
List<Member> lastMembers = memberService.getMembers(0, lastMembersCount);
if(lastMembers != null)
lastMembers.forEach(member -> {
System.out.println(member.[IN THIS PLACE I DONT HAWE ANY GETTERS for table field]);
});
But I don't have any getters in Member object. When I write member.getName()
I have error(IDEA suggested me to create getter 'getName()'). How to use lombook with jpa entity? How to access to field which was marked with lombok annotations like @Getter or @Setter ?
If you want to use 'lombok' you should install IDEA plugin and restart IDEA. After this simple steps, all will work nicely. Lombok is amazing
Enable "annotation processing".
Build, Execution, Deployment -> Compiler -> Annotation Processor: Enable annotation processing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.