Skip to content

JPA Problem jakarta.servlet.ServletException: Handler dispatch failed: java.lang.StackOverflowError #3045

@Glisa060

Description

@Glisa060

I'am sorry if this is the wrong place to report this problem but I feel there is a bug. Maybe it's me I don't know, problem happens on repository Save method. DTO is very simple just a field with String. Every entity has the same problem.

Generic Service

 @Transactional
  public DTO save(DTO DTO) {
    ID id = DTO.getId();
    if (id != null && !repository.existsById(id)) {
      throw new NotFoundException("ID not found");
    }

    return this.forceSave(DTO);
  }

  @Transactional
  public DTO forceSave(DTO DTO) {
      Model model = mapper.toModel(DTO);
      logger.info("DTO: {}", model.toString());
      return mapper.toDTO(repository.save(model));
  }

Mapper

@Mapper(componentModel = "spring")
public interface DrzavaMapper extends BaseMapper<Drzava, DrzavaDTO, Long> {}

Model

public class Drzava extends BaseEntity<Long> {

  @Column(nullable = false)
  private String ime;

  @OneToMany(mappedBy = "drzava")
  private Set<Grad> gradovi;
}
public class DrzavaDTO extends BaseDTO<Long> {
  @NotBlank(message = "Ime je obavezno")
  private String ime;
}

I use lombok but I omitted annotations just to make it easier to read. No @DaTa of course I know that causes recursion.
I tried @JsonIgnore @JsonBackReference an such to no avail.

@RestController
@RequestMapping("/drzave")
public class DrzavaController extends BaseController<Drzava, DrzavaDTO, Long> {
	private final DrzavaService service;

	public DrzavaController(DrzavaService service) {
		super(service);
		this.service = service;
	}
}

Steps:
http://localhost:8080/api/fakultet-service/drzave Post request

public DTO forceSave(DTO DTO) {
Model model = mapper.toModel(DTO);
logger.info("DTO: {}", model.toString());
return mapper.toDTO(repository.save(model)); << error happens here, repository.Save
}

Error: 2023-06-30T11:07:46.690+02:00 WARN 20984 --- [nio-8082-exec-7] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [jakarta.servlet.ServletException: Handler dispatch failed: java.lang.StackOverflowError]

It "Resolves" error without a stack trace which is ridiculous, how to solve if I don't have information what went wrong, no stack trace nothing. Tried debugging with steps, it takes too long.

Latest Spring Boot and Cloud 3.1.1, java 17, mysql connector java latest version 8.0.33.

Again I'am sorry if this is somehow my fault. I just want to solve this and move on. Thank you.

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions