Skip to content

SpringBeanContainer not called with Hibernate ORM 6.2 #30545

@vaclavsvejcar

Description

@vaclavsvejcar

Hello,

did something related to ApplicationContextAware behaviour change between Spring Boot 3.0.6 and 3.1.0? I have custom Hibernate IdentifierGenerator that also implements ApplicationContextAware because it's POJO to access the spring context:

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

@NonNullApi
public class SnowflakeIdentifierGenerator implements IdentifierGenerator, ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public Object generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return applicationContext.getBean(SnowflakeIdGenerator.class).nextId();  // NPE happens here
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

This works fine with Spring Boot 3.0.6, but after upgrading to 3.1.0, the ApplicationContext is always null.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions