private SessionFactory newLegacySessionFactory() { Properties properties = properties(); Configuration configuration = new Configuration().addProperties(properties); for (Class<?> entityClass : entities()) { configuration.addAnnotatedClass(entityClass); } String[] packages = packages(); if (packages != null) { for (String scannedPackage : packages) { configuration.addPackage(scannedPackage); } } String[] resources = resources(); if (resources != null) { for (String resource : resources) { configuration.addResource(resource); } } Interceptor interceptor = interceptor(); if (interceptor != null) { configuration.setInterceptor(interceptor); } final List<Type> additionalTypes = additionalTypes(); if (additionalTypes != null) { configuration.registerTypeContributor(new TypeContributor() { @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { for (Type type : additionalTypes) { if (type instanceof BasicType) { typeContributions.contributeType((BasicType) type); } else if (type instanceof UserType) { typeContributions.contributeType((UserType) type); } else if (type instanceof CompositeUserType) { typeContributions.contributeType((CompositeUserType) type); } } } }); } return configuration.buildSessionFactory( new StandardServiceRegistryBuilder() .applySettings(properties) .build() ); }