使用 JPA Spring Boot 计算表达式 intellij 时的 Stackoverflow

问题描述 投票:0回答:1

我今天问了一个问题,我创建了一个用户模型。

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "_user")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
public class User implements UserDetails {

  @Id
  @GeneratedValue
  private Integer id;
  private String firstname;
  private String lastname;
  @NotNull
  @Column(unique=true)
  private String email;
  @NotNull
  @Column(unique=true)
  private String usrname;

  @NotNull
  @ColumnDefault("'img/avatar1.jpg'")
  private String avatar;

  @JsonIgnore
  private String password;

  @Enumerated(EnumType.STRING)
  private Role role;

  @JsonIgnore
  @OneToMany(mappedBy = "user")
  private List<Token> tokens;

在我的服务中,我希望在评估方法时得到结果:

User updateUser = userRepository.getById(userId)
                .orElseThrow(() -> new ResourceNotFoundException("L'utilisateur n'existe pas avec l'id: " + userId));

这是我的 getById(userId)

@Query(value = "SELECT * FROM _user u where u.id = :id", nativeQuery = true)
  Optional<User> getById(int id);

当我评估方法以获得结果时,我得到了这个:

enter image description here

但是没有问题,因为我的代码继续执行..奇怪的事情,在控制台中,我没有StackOverflow问题..

我想进入调试模式并评估结果,因为我收到了

ERROR [https-jsse-nio-443-exec-3] c.d.x.ExceptionHandler: Could not commit JPA transaction
错误。


编辑

添加 fullstacktrace,我的 userId 是 int(1) 而不是字符串。

enter image description here

enter image description here

我希望有人遇到这个错误并解决它!

非常感谢

致以诚挚的问候

java spring jpa boot
1个回答
0
投票

根本原因可能是这个lombok问题,因为

toString()
方法默认是从控制台调试器调用的,并且它在不定式递归中失败,导致StackOverflowError。

© www.soinside.com 2019 - 2024. All rights reserved.