简体   繁体   English

Java - 无法设置字段值 [null, permissions=[]}]

[英]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.我有一个 class 用户,它有一个角色,角色有一个权限列表(枚举),当我尝试通过 ID 获取用户时出现错误,在我的数据库中数据正常。 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这解决了问题spring.jackson.serialization.fail-on-empty-beans=false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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