Example usage for org.hibernate.cfg Configuration addFile

List of usage examples for org.hibernate.cfg Configuration addFile

Introduction

In this page you can find the example usage for org.hibernate.cfg Configuration addFile.

Prototype

public Configuration addFile(File xmlFile) throws MappingException 

Source Link

Document

Read mappings from a particular XML file

Usage

From source file:org.joda.time.contrib.hibernate.TestPersistentInstant.java

License:Apache License

protected void setupConfiguration(Configuration cfg) {
    cfg.addFile(new File("src/test/java/org/joda/time/contrib/hibernate/thingWithInstant.hbm.xml"));
}

From source file:org.joda.time.contrib.hibernate.TestPersistentInstantAsBigInt.java

License:Apache License

protected void setupConfiguration(Configuration cfg) {
    cfg.addFile(new File("src/test/java/org/joda/time/contrib/hibernate/thingWithInstantAsBigInt.hbm.xml"));
}

From source file:org.joda.time.contrib.hibernate.TestPersistentInterval.java

License:Apache License

protected void setupConfiguration(Configuration cfg) {
    cfg.addFile(new File("src/test/java/org/joda/time/contrib/hibernate/plan.hbm.xml"));
}

From source file:org.joda.time.contrib.hibernate.TestPersistentPeriod.java

License:Apache License

protected void setupConfiguration(Configuration cfg) {
    cfg.addFile(
            new File("src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatHappens.hbm.xml"));
}

From source file:org.joda.time.contrib.hibernate.TestPersistentTimeOfDay.java

License:Apache License

protected void setupConfiguration(Configuration cfg) {
    cfg.addFile(new File("src/test/java/org/joda/time/contrib/hibernate/schedule.hbm.xml"));
}

From source file:org.openremote.model.persistence.jpa.H2.java

License:Open Source License

private static void addFiles(Configuration config, Set<String> files, URI filePath) {
    for (String mappingFile : files) {
        URI ormURI = filePath.resolve(filePath.getRawPath() + "/" + mappingFile);

        config.addFile(new File(ormURI));
    }//from  ww w  .  j  a  v  a 2 s.c  om
}

From source file:org.web4thejob.orm.CreateSchemaTest.java

License:Open Source License

@Test
public void schemaExportTest() throws IOException, SQLException {

    Log4jConfigurer.initLogging("classpath:org/web4thejob/conf/log4j.xml");

    Properties datasource = new Properties();
    datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream());

    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.DIALECT, datasource.getProperty(DatasourceProperties.DIALECT));
    configuration.setProperty(AvailableSettings.DRIVER, datasource.getProperty(DatasourceProperties.DRIVER));
    configuration.setProperty(AvailableSettings.URL, "jdbc:hsqldb:mem:mydb");
    configuration.setProperty(AvailableSettings.USER, datasource.getProperty(DatasourceProperties.USER));
    configuration.setProperty(AvailableSettings.PASS, datasource.getProperty(DatasourceProperties.PASSWORD));

    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();

    Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection();
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE SCHEMA w4tj;");
    statement.close();//www.j  ava  2s  .  co m

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) {

            if (resource.getFile().getName().equals("AuxiliaryDatabaseObjects.hbm.xml"))
                continue;

            configuration.addFile(resource.getFile());
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration);
    schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE);

    if (!schemaExport.getExceptions().isEmpty()) {
        throw new RuntimeException((Throwable) schemaExport.getExceptions().get(0));
    }

}