Hibernate 5.x to 6.3 migration breaks CustomIdGeneration

We had initially created a Custom id generator that would allow JPA entity manager to pass in an id and allow it to flow through to the DB on creation. In the case it was null, the DB’s autoincrement would create the ID and return the persisted entity with the created id.

The logic was similar to the AssignedIdentityGenerator mentioned here

The actual implementation looked something like so; found in the following stack overflow answer:

public class UseExistingIdOtherwiseGenerateUsingIdentity extends IdentityGenerator {

    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        Serializable id = session.getEntityPersister(null, object).getClassMetadata().getIdentifier(object, session);
        return id != null ? id : super.generate(session, object);
    }
}

After migrating to Hibernate Core 6.3.1.FINAL, there doesn’t seem to be a way to create an identity generator that respects the requested id generator.
When trying to return a null from the recommended IdentifierGenerator, then an exception is thrown stating that null is not allowed.

I have also tried to return POST_INSERT_INDICATOR, but that doesn’t seem to be supported since Hibernate 6.2:

public class UseExistingIdOtherwiseGenerateUsingIdentity extends IdentityGenerator {

    @Override
    public Object generate(SharedSessionContractImplementor session, Object object) {
        Serializable id = (Serializable) session.getEntityPersister(null, object).getClassMetadata().getIdentifier(object, session);
        return id != null ? id : IdentifierGeneratorHelper.POST_INSERT_INDICATOR;
    }
}

Tracing through the code, I only see option to pass in IdentifierGeneratorHelper.SHORT_CIRCUIT_INDICATOR, but that doesn’t work either as it created an entity with a null id which isn’t managed by Hibernate.

Any advice would be appreciated.