[hibernate-dev] OGM options and ORM 5 bootstrap

Gunnar Morling gunnar at hibernate.org
Thu Jul 2 07:53:48 EDT 2015


Hi Emmanuel, all,

Prior to ORM 5, we used to have OgmConfiguration (sub-class of the dreaded
Configuration), which provided an entry point into our custom option API:

    OgmConfiguration config = ...
    config.configureOptionsFor( MongoDB.class )
        .associationStorage(IN_ENTITY)
        ...
    OgmSessionFactory osf = config.buildSessionFactory();

Now as of my current in-flight branch of migrating over to ORM 5, the
equivalent is writing a configurator callback (which also is the only way
today to do it under JPA):

    public class MyConfigurator extends OptionConfigurator {
        public void configure(Configurable configurable) {
            configurable.configureOptionsFor( MongoDB.class )
                .associationStorage(IN_ENTITY)
        }
    }

And then plugging it in like so:

    OgmSessionFactory osf = new MetadataSources(
        new StandardServiceRegistryBuilder()
                .applySetting( "hibernate.ogm.option.configurator",
MyConfigurator.class )
                .build();
         )
        .buildMetadata()
        .getSessionFactoryBuilder()
        .unwrap( OgmSessionFactoryBuilder.class )
        .build();

Do you consider that good enough? The alternative would be providing our
own OgmStandardServiceRegistryBuilder or some unwrap on
StandardServiceRegistryBuilder (it has to be that early, because the
datastore provider service lives in that service registry, and it may
consume settings such as the global write concern which is passed to
MongoDB when connecting). Personally I think what we have is good enough.

Thanks,

--Gunnar


More information about the hibernate-dev mailing list