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
How to have more than one Integrators say MetadataExtractorIntegrator and EventListenerIntegrator.
How to configure incase of CustomLocalSessionFactoryBean (extends LocalSessionFactoryBean).
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;
}