You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot获取数据库主题列表时出现4类错误求助

问题详情

我正在开发一个练习用API,用Postman能正常保存实体及关联关系,API集成的JWT也能正常生成访问令牌。但调用GET接口获取所有主题时,控制台抛出4个错误:

  • java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
  • java.lang.StackOverflowError: null
  • org.springframework.security.access.AccessDeniedException: Access Denied
  • jakarta.servlet.ServletException: Unable to handle the Spring Security Exception because the response is already committed

注意:获取主题的端点是公开的,无权限限制。

实体类代码

用户实体

@Table(name="usuario", uniqueConstraints = {@UniqueConstraint(columnNames = {"username","email"})}) 
@Entity 
public class Usuario implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id_usuario;
    private String nombre;
    private String apellido;
    private String curso;
    private String username;
    private String password;
    private String email;

    @Enumerated(EnumType.STRING)
    private Role rol;

    @OneToMany (mappedBy = "usu", cascade = CascadeType.ALL)
    private List<Topico> lista_topicos;


    @OneToMany (mappedBy = "usu_respuesta", cascade = CascadeType.ALL)
    private List<Respuesta> lista_respuestas;
}

主题实体

@Entity
public class Topico {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id_topico;
    @Column(nullable = false)
    private String titulo;
    @Column(nullable = false)
    private String mensaje;
    @Temporal(TemporalType.DATE)
    private Date fecha_creacion;
    @Convert(converter = TrueFalseConverter.class)
    private boolean estado;

    @ManyToOne
    @Cascade(org.hibernate.annotations.CascadeType.MERGE)
    @JoinColumn(name = "usu_id")
    private Usuario usu;

    @OneToMany (mappedBy = "topic", cascade = CascadeType.ALL)
    private List<Respuesta> lista_respuesta;
}

回复实体

@Entity
public class Respuesta {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id_respuesta;
    private String texto_respuesta;

    @ManyToOne
    @Cascade(org.hibernate.annotations.CascadeType.MERGE)
    @JoinColumn(name = "topico_id")
    private Topico topic;

    @ManyToOne
    @Cascade(org.hibernate.annotations.CascadeType.MERGE)
    @JoinColumn(name="user_id")
    private Usuario usu_respuesta;
}

内容的提问来源于stack exchange,提问作者Juan Bravo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 22:22:38