Вот код для роли enum и сущность User:
public enum Role {
ADMIN, DRIVER, RIDER
}
< /code>
@Entity
@Getter
@Setter
@Table(name = "app_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@Column(unique = true)
private String email;
private String password;
@ElementCollection(fetch = FetchType.LAZY)
@Enumerated(EnumType.STRING)
private Set roles;
}
< /code>
Problem:
Despite the roles field being defined as a Set, Lombok is generating a setter method that accepts List instead of Set. The generated setter method signature looks like this:
public void setRoles(List roles);
public List getRoles();
< /code>
What I’ve tried:
- I have declared the roles field as a Set.
- I am using the latest version of Lombok and Spring Boot.
- The Role enum is of type String.
Why does Lombok generate a setter method that accepts List instead of Set for the roles field, even though the field is a Set? How can I fix this and ensure that the setter accepts a Set?
Подробнее здесь: https://stackoverflow.com/questions/793 ... -in-my-jpa
Мобильная версия