我有一个类USER,它有一个角色,角色有一个权限列表(枚举),当我尝试通过ID获取用户时,我得到了一个错误!在我的数据库中的数据是好的,我有一个角色创建的用户。
@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
1条答案
按热度按时间b91juud31#
这解决了问题spring.jackson.serialization.fail-on-empty-beans=false