springhibernatespring-data-jpavaadin

HHH000506: Detaching an uninitialized collection with enabled filters from a session


Any pointers on what this warning is trying to tell me, and how to make it go away, would be appreciated.

I'm running a spring boot with data-jpa application, using Vaadin as the UI, and I'm seeing a lot of HHH000506 warnings. Googling for this, there are almost no results, so apparently this is special. I do not like being special.

2025-04-03 23:45:34,034 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Provider.availabilities#1]
2025-04-03 23:45:34,035 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Provider.topics#1]
2025-04-03 23:45:34,035 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Provider.availabilities#2]
2025-04-03 23:45:34,035 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Provider.topics#2]
...
2025-04-03 23:45:34,145 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Provider.topics#2]
2025-04-03 23:45:34,147 {      test} WARN  [http-nio-8080-exec-2] org.hibernate.collection.spi.AbstractPersistentCollection: HHH000506: Detaching an uninitialized collection with enabled filters from a session: [nl.softworks.consilio.domain.Group.consumers#3]

These are in-the-hunderdes of lines, it seems all the collections of all loaded entities trigger it. For the first lines:

@Entity
public class Provider extends BaseTenantEntity<Provider>
    @ManyToMany
    @JoinTable(name = "provider_topic",
            joinColumns = @JoinColumn(name = "provider_id"),
            inverseJoinColumns = @JoinColumn(name = "topic_id"))
    private Set<Topic> topics;

    @OneToMany(mappedBy="provider", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<ProviderAvailability> availabilities;
}

@MappedSuperclass
public class BaseTenantEntity<T> extends BaseEntity<T> {
    @TenantId
    private String tenant;
}

@MappedSuperclass
public class BaseEntity<T> {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    protected long id;

    @Version
    private long lazylock;
}

I kinda can grasp what the error tries to say, but then I'd expect an = new HashSet() assignment to be present, which clearly is not the case. But the part about filtering does not make sense. I do have a @TenantId annotation on the entity, but it also complains on entities that do not have a that.

The error occurs upon a read call to the Spring data-jpa generated repository:

providers = providerRepo.findAllByPeriodOrderByCode(period);

public interface ProviderRepo extends JpaRepository<Provider, Long> {
    List<Provider> findAllByPeriodOrderByCode(Period period);
    Provider findByCode(String code);
}

The application is mostly CRUD, so there is no transactional service, just a save call on the repository. But save is not an issue, it's the find that shows these warnings.

Vaadin 24.5 includes spring-boot-starter-* 3.4.3


Solution

  • This message warns you that:

    Therefore, if you try to access the collection it will initialize but the filters won't apply.
    You can refer to the discussion in https://hibernate.atlassian.net/browse/HHH-11076 for more details