I am using Spring Boot together with JPA. When logging.level.org.springframework.web=DEBUG is set, fetching an entity via JPQL fetches lazy-loaded fields via SQL, even if they are annotated with @JsonIgnore.

Example:

@Entity
public class Author {
    @Id
    private UUID id;

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "author", fetch = FetchType.LAZY)
    private List<Book> books;

    @Column
    private UUID groupId;
}

@Entity
public class Book {
    @ManyToOne
    private Author author;
}

public interface AuthorRepository extends JpaRepository<Author, UUID> {
    @Query("SELECT a FROM Author a WHERE a.groupId IN :groupIds")
    Page findByGroupIds(@Param("groupIds") Set<UUID> groupIds, Pageable pageable);
}

AuthorRepository.findByGroupIds will generate a query to fetch all the authors in the specified groupId set. If logging.level.org.springframework.web=DEBUG is set, it will also generate a query to fetch the books of each author, even though it is lazy and annotated with @JsonIgnore.

If this is expected behaviour, I think these side-effects should at least be documented.

Comment From: snicoll

You haven't shared the actual log. It looks like a toString may be the problem and, if so, there's nothing we'll be able to fix here. Can you share a small sample rather than code in text?

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.