Example usage for org.hibernate.cfg AvailableSettings GLOBALLY_QUOTED_IDENTIFIERS

List of usage examples for org.hibernate.cfg AvailableSettings GLOBALLY_QUOTED_IDENTIFIERS

Introduction

In this page you can find the example usage for org.hibernate.cfg AvailableSettings GLOBALLY_QUOTED_IDENTIFIERS.

Prototype

String GLOBALLY_QUOTED_IDENTIFIERS

To view the source code for org.hibernate.cfg AvailableSettings GLOBALLY_QUOTED_IDENTIFIERS.

Click Source Link

Document

Should all database identifiers be quoted.

Usage

From source file:org.wallride.tools.Hbm2ddl.java

License:Apache License

public static void main(String[] args) throws Exception {
    String locationPattern = "classpath:/org/wallride/domain/*";

    final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
    final MetadataSources metadataSources = new MetadataSources(registry);
    final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry);

    registryBuilder.applySetting(AvailableSettings.DIALECT,
            ExtendedMySQL5InnoDBDialect.class.getCanonicalName());
    registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true);
    registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY,
            PhysicalNamingStrategySnakeCaseImpl.class);

    final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    final Resource[] resources = resourcePatternResolver.getResources(locationPattern);
    final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    for (Resource resource : resources) {
        MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
        AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
        if (metadata.hasAnnotation(Entity.class.getName())) {
            metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName()));
        }/*from   w  w  w .ja  va 2 s.  c o m*/
    }

    final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build();
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl);

    new SchemaExport().setHaltOnError(true).setDelimiter(";").create(EnumSet.of(TargetType.STDOUT),
            metadataBuilder.build());
}