简体   繁体   中英

Java - Could not set field value [null, permissions=[]}]

I have a class User, that have a Role, role have a list of permission (enum), when i try to get a User by ID i get an error, In my database the data is OK. i have an user with a rol created.

@Getter
@Setter
@Entity
@Table(name = "usuarios")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String password;
    @ManyToOne(targetEntity= com.ecommerce.model.Role.class)
    private Role role;
@Getter
@Setter
@Entity
@Table(name = "roles")
public class Role {
    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "rol")
    @Enumerated(EnumType.STRING)
    private RoleType role;
    @Column(name = "permisos")
    @Enumerated(EnumType.STRING)
    @ElementCollection(targetClass = Permission.class)
    private List<Permission> permissions;
public enum RoleType {
    manager,
    seller,
    buyer
}
There was an unexpected error (type=Internal Server Error, status=500).
Could not set field value [null, permissions=[]}] value by reflection : [class com.ecommerce.model.User.role] setter of com.ecommerce.model.User.role; nested exception is org.hibernate.PropertyAccessException: Could not set field value [null, permissions=[]}] value by reflection : [class com.ecommerce.model.User.role] setter of com.ecommerce.model.User.role
org.springframework.orm.jpa.JpaSystemException: Could not set field value [null, permissions=[]}] value by reflection : [class com.ecommerce.model.User.role] setter of com.ecommerce.model.User.role; nested exception is org.hibernate.PropertyAccessException: Could not set field value [null, permissions=[]}] value by reflection : [class com.ecommerce.model.User.role] setter of com.ecommerce.model.User.role

this solves the problem spring.jackson.serialization.fail-on-empty-beans=false

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM