Hibernate 5: getCollectionMappings from Configuration

https://docs.jboss.org/hibernate/orm/4.0/javadocs/org/hibernate/cfg/Configuration.html

Before hibernate 5 we could use getCollectionMappings using Configuration class.
However, I am unable to find collection mapping.
Can someone, let me know the replacement for getCollectionMappings().

The below link was very informative and i feel it fits my case


But i am unable to get my code working

  1. How to have more than one Integrators say MetadataExtractorIntegrator and EventListenerIntegrator.
  2. How to configure incase of CustomLocalSessionFactoryBean (extends LocalSessionFactoryBean).
  3. How to get/modify getCollectionMappings from configuration ?

Here is my old code which i am trying to replace
@Override
protected void postProcessConfiguration(Configuration config) {
super.postProcessConfiguration(config);

    if (!DatabasePlatform.INVENTORY_SCHEMA.equals(DatabasePlatform.DEFAULT_INVENTORY_SCHEMA)) {
        logger.info("Overriding inventory schema name to %s", DatabasePlatform.INVENTORY_SCHEMA);
        Iterator<PersistentClass> classIterator = config.getClassMappings();

        while (classIterator.hasNext()) {
            PersistentClass persistentClass = classIterator.next();
            replaceSchemaName(persistentClass.getTable());
            Iterator<Join> joinIterator = persistentClass.getJoinIterator();
            while (joinIterator.hasNext()) {
                replaceSchemaName(joinIterator.next().getTable());
            }

            Iterator<org.hibernate.mapping.Collection> collectionIterator = config.getCollectionMappings();
            while (collectionIterator.hasNext()) {
                replaceSchemaName(collectionIterator.next().getCollectionTable());
            }
        }
    }
}

private void replaceSchemaName(Table table) {
    if (DatabasePlatform.DEFAULT_INVENTORY_SCHEMA.equals(table.getSchema())) {
        table.setSchema(DatabasePlatform.INVENTORY_SCHEMA);
    }
    if (table.getName().startsWith(DatabasePlatform.DEFAULT_INVENTORY_SCHEMA + ".")) {
        table.setName(table.getName().replaceFirst(DatabasePlatform.DEFAULT_INVENTORY_SCHEMA, DatabasePlatform.INVENTORY_SCHEMA));
    }
}

I am replacing Earlier
public class CustomHibernateSessionFactoryBean extends org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean {
with
public class CustomHibernateSessionFactoryBean extends org.springframework.orm.hibernate5.LocalSessionFactoryBean {

I am getting metadata as null.
Where to hook in my code such that metadata is not null?
@ Override

public MetadataSources getMetadataSources() {
    this.setMetadataSourcesAccessed(true);
    if (this.metadataSources == null) {
        BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder()
                .applyIntegrator(EventListenerIntegrator.INSTANCE)
                .applyIntegrator(MetadataExtractorIntegrator.INSTANCE);
        if (this.resourcePatternResolver != null) {
            builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
        }
        builder.build();
        this.metadataSources = new MetadataSources();
    }
    configureDatabase();
    return this.metadataSources;
}

How to have more than one Integrators say MetadataExtractorIntegrator and EventListenerIntegrator.

You can define multiple Integrator objects via the hibernate.integrator_provider property.

How to configure incase of CustomLocalSessionFactoryBean (extends LocalSessionFactoryBean).

That’s a question you need to ask on the Spring forum.

How to get/modify getCollectionMappings from configuration

Use the EntityMetamodel and check its properties and check properties[i].getType().isCollectionType().