private static StandardServiceRegistry getStandardServiceRegistry( ServiceRegistry serviceRegistry) { if (serviceRegistry == null) { throw new HibernateException("ServiceRegistry passed to MetadataBuilder cannot be null"); } if (StandardServiceRegistry.class.isInstance(serviceRegistry)) { return (StandardServiceRegistry) serviceRegistry; } else if (BootstrapServiceRegistry.class.isInstance(serviceRegistry)) { log.debugf( "ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" + "if attempt is made to build SessionFactory"); return new StandardServiceRegistryBuilder((BootstrapServiceRegistry) serviceRegistry).build(); } else { throw new HibernateException( String.format( "Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder", serviceRegistry.getClass().getName())); } }