Skip to content

Memory leak using enums in native query #3816

@tsavaph

Description

@tsavaph

Using the native query in code below I've found a memory leak.

@Service
@RequiredArgsConstructor
public class TestService {

    private final List<Status> statuses = List.of(Status.NOT_ACTIVE, Status.ACTIVE);
    private final TestRepository repository;

    @Transactional
    public void test() {
        var result = repository.findByStatusForUpdate(statuses);
        // todo
    }

}

public interface TestRepository extends JpaRepository<TestEntity, Long> {

    @Query(value = "SELECT * FROM test WHERE status_dict_id in (:statuses) FOR UPDATE SKIP LOCKED", nativeQuery = true)
    List<TestEntity> findByStatusForUpdate(List<Status> statuses);

}

@Entity
public class TestEntity {

    @Id
    private Long id;

    @Column(name = "status_dict_id")
    @Enumerated(EnumType.ORDINAL)
    private Status status;

}

public enum Status {

    UNDEFINED,
    BLOCKED,
    ACTIVE,
    NOT_ACTIVE,

}

Hibernate keeps statuses and and consumes memory. Database - postgres.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions