Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak using enums in native query #3816

Closed
tsavaph opened this issue Mar 15, 2025 · 4 comments
Closed

Memory leak using enums in native query #3816

tsavaph opened this issue Mar 15, 2025 · 4 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@tsavaph
Copy link

tsavaph commented Mar 15, 2025

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2025
@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Mar 17, 2025
@mp911de
Copy link
Member

mp911de commented Mar 17, 2025

How does a memory accumulation relate to Spring Data? Have you tried without Spring Data?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 17, 2025
@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 17, 2025
@tsavaph
Copy link
Author

tsavaph commented Mar 17, 2025

How does a memory accumulation relate to Spring Data? Have you tried without Spring Data?

My fault :), it is only a Hibernate issue. Tried pure Hibernate config without spring-data-jpa - same problem, high heap accumulation.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 17, 2025
@schauder
Copy link
Contributor

If you open a ticket with Hibernate, please leave a link here, so others have a better chance of finding it.

Thanks

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2025
@schauder schauder added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Mar 18, 2025
@tsavaph
Copy link
Author

tsavaph commented Mar 26, 2025

Created a bug for Hibernate https://hibernate.atlassian.net/browse/HHH-19276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants