Java Code Examples for org.hibernate.cfg.Configuration#addClass()

The following examples show how to use org.hibernate.cfg.Configuration#addClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateTemplate.java    From MogwaiERDesignerNG with GNU General Public License v3.0 6 votes vote down vote up
protected Configuration createConfiguration(Class aHibernateDialectClass) {
    Configuration theConfiguration = new Configuration();
    theConfiguration.addClass(DomainEntity.class);
    theConfiguration.addClass(CustomTypeEntity.class);
    theConfiguration.addClass(TableEntity.class);
    theConfiguration.addClass(AttributeEntity.class);
    theConfiguration.addClass(IndexEntity.class);
    theConfiguration.addClass(RelationEntity.class);
    theConfiguration.addClass(CommentEntity.class);
    theConfiguration.addClass(SubjectAreaEntity.class);
    theConfiguration.addClass(RepositoryEntity.class);
    theConfiguration.addClass(ChangeEntity.class);
    theConfiguration.addClass(ViewEntity.class);
    theConfiguration.setProperty(Environment.DIALECT, aHibernateDialectClass.getName());
    theConfiguration.setProperty(Environment.HBM2DDL_AUTO, "update");
    theConfiguration.setProperty(Environment.CONNECTION_PROVIDER, ThreadbasedConnectionProvider.class.getName());
    return theConfiguration;
}
 
Example 2
Source File: IndexCreator.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private SessionFactory createSessionFactory(String url, String login, String passwd, String dialect, String driverClass, String mappedClasses) throws MappingException, ClassNotFoundException {
	Configuration cfg = new Configuration();
	for (String className:mappedClasses.split(",")) {
		cfg.addClass(Class.forName(className));
	}
	cfg.setProperty("hibernate.current_session_context_class", "thread");
	cfg.setProperty("hibernate.transaction.factory_class","org.hibernate.transaction.JDBCTransactionFactory");
	cfg.setProperty("hibernate.connection.driver_class", driverClass);
	cfg.setProperty("hibernate.connection.password", passwd);
	cfg.setProperty("hibernate.connection.username", login);
	cfg.setProperty("hibernate.default_schema", "PUBLIC");
	cfg.setProperty("hibernate.connection.url", url);
	return  cfg.buildSessionFactory();
}
 
Example 3
Source File: IndexCreator.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
private SessionFactory createSessionFactory(String url, String login, String passwd, String dialect, String driverClass, String mappedClasses) throws MappingException, ClassNotFoundException {
	Configuration cfg = new Configuration();
	for (String className:mappedClasses.split(",")) {
		cfg.addClass(Class.forName(className));
	}
	cfg.setProperty("hibernate.current_session_context_class", "thread");
	cfg.setProperty("hibernate.transaction.factory_class","org.hibernate.transaction.JDBCTransactionFactory");
	cfg.setProperty("hibernate.connection.driver_class", driverClass);
	cfg.setProperty("hibernate.connection.password", passwd);
	cfg.setProperty("hibernate.connection.username", login);
	cfg.setProperty("hibernate.default_schema", "PUBLIC");
	cfg.setProperty("hibernate.connection.url", url);
	return  cfg.buildSessionFactory();
}
 
Example 4
Source File: HibernateEngine.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void configureSession(Properties props, List<Class> classes) {
    Configuration cfg = new Configuration();
    cfg.setProperties(props);

    if (classes != null) {
        for (Class className : classes) {
            cfg.addClass(className);
        }
    }

    _factory = cfg.buildSessionFactory();         // get a session context        

    // check tables exist and are of a matching format to the persisted objects
    new SchemaUpdate(cfg).execute(false, true);
}
 
Example 5
Source File: HibernateEngine.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** initialises hibernate and the required tables */
private void initialise(Set<Class> classes, Properties props) throws HibernateException {
    try {
        Configuration _cfg = new Configuration();

        // if props supplied, use them instead of hibernate.properties
        if (props != null) {
            _cfg.setProperties(props);
        }

        // add each persisted class to config
        for (Class persistedClass : classes) {
            _cfg.addClass(persistedClass);
        }

        // get a session context
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(_cfg.getProperties()).build();
        _factory = _cfg.buildSessionFactory(serviceRegistry);

        // check tables exist and are of a matching format to the persisted objects
        new SchemaUpdate(_cfg).execute(false, true);

    }
    catch (MappingException me) {
        _log.error("Could not initialise database connection.", me);
    }
}
 
Example 6
Source File: OLATLocalSessionFactoryBean.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
    try {
        if (additionalDBMappings != null && additionalDBMappings.length > 0) {
            for (AdditionalDBMappings addMapping : additionalDBMappings) {
                List<String> xmlFiles = addMapping.getXmlFiles();
                if (xmlFiles != null) {
                    for (String mapping : xmlFiles) {
                        // we cannot access the classloader magic used by the LocalSessionFactoryBean
                        Resource resource = new ClassPathResource(mapping.trim());
                        config.addInputStream(resource.getInputStream());
                    }
                }

                List<Class<?>> annotatedClasses = addMapping.getAnnotatedClasses();
                if (annotatedClasses != null) {
                    for (Class<?> annotatedClass : annotatedClasses) {
                        config.addClass(annotatedClass);
                    }
                }
            }
        }
        super.postProcessMappings(config);
    } catch (Exception e) {
        log.error("Error during the post processing of the hibernate session factory.", e);
    }
}
 
Example 7
Source File: OLATLocalSessionFactoryBean.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
    try {
        if (additionalDBMappings != null && additionalDBMappings.length > 0) {
            for (AdditionalDBMappings addMapping : additionalDBMappings) {
                List<String> xmlFiles = addMapping.getXmlFiles();
                if (xmlFiles != null) {
                    for (String mapping : xmlFiles) {
                        // we cannot access the classloader magic used by the LocalSessionFactoryBean
                        Resource resource = new ClassPathResource(mapping.trim());
                        config.addInputStream(resource.getInputStream());
                    }
                }

                List<Class<?>> annotatedClasses = addMapping.getAnnotatedClasses();
                if (annotatedClasses != null) {
                    for (Class<?> annotatedClass : annotatedClasses) {
                        config.addClass(annotatedClass);
                    }
                }
            }
        }
        super.postProcessMappings(config);
    } catch (Exception e) {
        log.error("Error during the post processing of the hibernate session factory.", e);
    }
}