List of usage examples for org.hibernate.cfg Configuration addInputStream
public Configuration addInputStream(InputStream xmlInputStream) throws MappingException
From source file:com.frameworkset.common.poolman.hibernate.LocalSessionFactoryBean.java
License:Apache License
@Override @SuppressWarnings("unchecked") protected SessionFactory buildSessionFactory() throws Exception { // Create Configuration instance. Configuration config = newConfiguration(); DataSource dataSource = getDataSource(); if (dataSource != null) { this.configTimeDataSourceHolder.set(dataSource); }// w ww. ja v a 2 s . co m // Analogous to Hibernate EntityManager's Ejb3Configuration: // Hibernate doesn't allow setting the bean ClassLoader explicitly, // so we need to expose it as thread context ClassLoader accordingly. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.beanClassLoader != null && !this.beanClassLoader.equals(threadContextClassLoader)); try { if (overrideClassLoader) { currentThread.setContextClassLoader(this.beanClassLoader); } if (this.entityInterceptor != null) { // Set given entity interceptor at SessionFactory level. config.setInterceptor(this.entityInterceptor); } if (this.namingStrategy != null) { // Pass given naming strategy to Hibernate Configuration. config.setNamingStrategy(this.namingStrategy); } if (this.configLocations != null) { for (Resource resource : this.configLocations) { // Load Hibernate configuration from given location. config.configure(resource.getURL()); } } if (this.hibernateProperties != null) { // Add given Hibernate properties to Configuration. Properties temp = new Properties(); temp.putAll(this.hibernateProperties); config.addProperties(temp); } if (dataSource != null) { Class providerClass = LocalDataSourceConnectionProvider.class; config.setProperty(Environment.CONNECTION_PROVIDER, providerClass.getName()); } if (this.mappingResources != null) { // Register given Hibernate mapping definitions, contained in resource files. for (String mapping : this.mappingResources) { Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader); config.addInputStream(resource.getInputStream()); } } if (this.mappingLocations != null) { // Register given Hibernate mapping definitions, contained in resource files. for (Resource resource : this.mappingLocations) { config.addInputStream(resource.getInputStream()); } } if (this.cacheableMappingLocations != null) { // Register given cacheable Hibernate mapping definitions, read from the file system. for (Resource resource : this.cacheableMappingLocations) { config.addCacheableFile(resource.getFile()); } } if (this.mappingJarLocations != null) { // Register given Hibernate mapping definitions, contained in jar files. for (Resource resource : this.mappingJarLocations) { config.addJar(resource.getFile()); } } if (this.mappingDirectoryLocations != null) { // Register all Hibernate mapping definitions in the given directories. for (Resource resource : this.mappingDirectoryLocations) { File file = resource.getFile(); if (!file.isDirectory()) { throw new IllegalArgumentException( "Mapping directory location [" + resource + "] does not denote a directory"); } config.addDirectory(file); } } // Tell Hibernate to eagerly compile the mappings that we registered, // for availability of the mapping information in further processing. postProcessMappings(config); config.buildMappings(); if (this.entityCacheStrategies != null) { // Register cache strategies for mapped entities. for (Enumeration classNames = this.entityCacheStrategies.propertyNames(); classNames .hasMoreElements();) { String className = (String) classNames.nextElement(); String[] strategyAndRegion = SimpleStringUtil .commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className)); if (strategyAndRegion.length > 1) { // method signature declares return type as Configuration on Hibernate 3.6 // but as void on Hibernate 3.3 and 3.5 Method setCacheConcurrencyStrategy = Configuration.class .getMethod("setCacheConcurrencyStrategy", String.class, String.class, String.class); ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, config, new Object[] { className, strategyAndRegion[0], strategyAndRegion[1] }); } else if (strategyAndRegion.length > 0) { config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]); } } } if (this.collectionCacheStrategies != null) { // Register cache strategies for mapped collections. for (Enumeration collRoles = this.collectionCacheStrategies.propertyNames(); collRoles .hasMoreElements();) { String collRole = (String) collRoles.nextElement(); String[] strategyAndRegion = SimpleStringUtil .commaDelimitedListToStringArray(this.collectionCacheStrategies.getProperty(collRole)); if (strategyAndRegion.length > 1) { config.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0], strategyAndRegion[1]); } else if (strategyAndRegion.length > 0) { config.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0]); } } } if (this.eventListeners != null) { // Register specified Hibernate event listeners. for (Map.Entry<String, Object> entry : this.eventListeners.entrySet()) { String listenerType = entry.getKey(); Object listenerObject = entry.getValue(); if (listenerObject instanceof Collection) { Collection<Object> listeners = (Collection<Object>) listenerObject; EventListeners listenerRegistry = config.getEventListeners(); Object[] listenerArray = (Object[]) Array .newInstance(listenerRegistry.getListenerClassFor(listenerType), listeners.size()); listenerArray = listeners.toArray(listenerArray); config.setListeners(listenerType, listenerArray); } else { config.setListener(listenerType, listenerObject); } } } // Perform custom post-processing in subclasses. postProcessConfiguration(config); // Build SessionFactory instance. logger.info("Building new Hibernate SessionFactory"); this.configuration = config; return newSessionFactory(config); } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } configTimeDataSourceHolder.set(null); } }
From source file:com.liferay.portal.spring.hibernate.PortalExtletHibernateConfiguration.java
License:Open Source License
@Override protected Configuration newConfiguration() { Configuration configuration = super.newConfiguration(); ClassLoader classLoader = getConfigurationClassLoader(); String resourceName = EXTLET_HIBERNATE_RESOURCE_NAME; try {//from w w w . j a va 2 s .c om Enumeration<URL> resources = classLoader.getResources(resourceName); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); try { if (_log.isDebugEnabled()) { _log.debug("Loading extlet-hbm.xml from: " + resource); } InputStream is = new UrlResource(resource).getInputStream(); if (is != null) { try { configuration.addInputStream(is); } finally { is.close(); } } if (_log.isDebugEnabled()) { _log.debug("Loading OK: " + resource); } } catch (Exception e2) { if (_log.isWarnEnabled()) { _log.warn("Problem while loading " + resource, e2); } } } } catch (Exception e2) { if (_log.isWarnEnabled()) { _log.warn("Problem while loading classLoader resources: " + resourceName, e2); } } return configuration; }
From source file:com.liferay.portal.spring.hibernate.PortalHibernateConfiguration.java
License:Open Source License
protected void readResource(Configuration configuration, String resource, InputStream is) throws Exception { if (is == null) { return;//from w ww. j a va 2 s .c om } if (_hibernateConfigurationConverter != null) { String configurationString = StringUtil.read(is); is.close(); configurationString = _hibernateConfigurationConverter.convert(configurationString); is = new UnsyncByteArrayInputStream(configurationString.getBytes()); } configuration = configuration.addInputStream(is); is.close(); }
From source file:com.wavemaker.tools.data.ExportDB.java
License:Open Source License
@Override protected void customRun() { init();/*from w w w. ja v a 2s . c o m*/ final Configuration cfg = new Configuration(); // cfg.addDirectory(this.hbmFilesDir); this.hbmFilesDir.find().files().performOperation(new ResourceOperation<com.wavemaker.tools.io.File>() { @Override public void perform(com.wavemaker.tools.io.File file) { if (file.getName().endsWith(".hbm.xml")) { cfg.addInputStream(file.getContent().asInputStream()); } } }); Properties connectionProperties = getHibernateConnectionProperties(); cfg.addProperties(connectionProperties); SchemaExport export = null; SchemaUpdate update = null; File ddlFile = null; try { if (this.overrideTable) { Callable<SchemaExport> t = new Callable<SchemaExport>() { @Override public SchemaExport call() { return new SchemaExport(cfg); } }; if (this.classesDir == null) { try { export = t.call(); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } } else { export = ResourceClassLoaderUtils.runInClassLoaderContext(true, t, this.classesDir); } ddlFile = File.createTempFile("ddl", ".sql"); ddlFile.deleteOnExit(); export.setOutputFile(ddlFile.getAbsolutePath()); export.setDelimiter(";"); export.setFormat(true); String extraddl = prepareForExport(this.exportToDatabase); export.create(this.verbose, this.exportToDatabase); this.errors = CastUtils.cast(export.getExceptions()); this.errors = filterError(this.errors, connectionProperties); this.ddl = IOUtils.read(ddlFile); if (!ObjectUtils.isNullOrEmpty(extraddl)) { this.ddl = extraddl + "\n" + this.ddl; } } else { Callable<SchemaUpdate> t = new Callable<SchemaUpdate>() { @Override public SchemaUpdate call() { return new SchemaUpdate(cfg); } }; if (this.classesDir == null) { try { update = t.call(); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } } else { update = ResourceClassLoaderUtils.runInClassLoaderContext(t, this.classesDir); } prepareForExport(this.exportToDatabase); Connection conn = JDBCUtils.getConnection(this.connectionUrl.toString(), this.username, this.password, this.driverClassName); Dialect dialect = Dialect.getDialect(connectionProperties); DatabaseMetadata meta = new DatabaseMetadata(conn, dialect); String[] updateSQL = cfg.generateSchemaUpdateScript(dialect, meta); update.execute(this.verbose, this.exportToDatabase); this.errors = CastUtils.cast(update.getExceptions()); StringBuilder sb = new StringBuilder(); for (String line : updateSQL) { sb = sb.append(line); sb = sb.append("\n"); } this.ddl = sb.toString(); } } catch (IOException ex) { throw new DataServiceRuntimeException(ex); } catch (SQLException qex) { throw new DataServiceRuntimeException(qex); } catch (RuntimeException rex) { if (rex.getCause() != null && rex.getCause().getMessage().contains(NO_SUITABLE_DRIVER) && WMAppContext.getInstance().isCloudFoundry()) { String msg = rex.getMessage() + " - " + UNKNOWN_DATABASE; throw new DataServiceRuntimeException(msg); } else { throw new DataServiceRuntimeException(rex); } } finally { try { ddlFile.delete(); } catch (Exception ignore) { } } }
From source file:it.doqui.index.ecmengine.business.personalization.hibernate.RoutingLocalSessionFactoryBean.java
License:Open Source License
protected SessionFactory buildSessionFactory() throws Exception { logger.debug("[RoutingLocalSessionFactoryBean::buildSessionFactory] BEGIN"); SessionFactory sf = null;// w w w . ja va2 s. com // Create Configuration instance. Configuration config = newConfiguration(); DataSource currentDataSource = getCurrentDataSource(); logger.debug("[RoutingLocalSessionFactoryBean::buildSessionFactory] " + "Repository '" + RepositoryManager.getCurrentRepository() + "' -- Got currentDataSource: " + currentDataSource); if (currentDataSource == null) { throw new IllegalStateException("Null DataSource!"); } // Make given DataSource available for SessionFactory configuration. logger.debug("[RoutingLocalSessionFactoryBean::buildSessionFactory] " + "Thread '" + Thread.currentThread().getName() + "' -- Setting DataSource for current thread: " + currentDataSource); CONFIG_TIME_DS_HOLDER.set(currentDataSource); if (this.jtaTransactionManager != null) { // Make Spring-provided JTA TransactionManager available. CONFIG_TIME_TM_HOLDER.set(this.jtaTransactionManager); } if (this.lobHandler != null) { // Make given LobHandler available for SessionFactory configuration. // Do early because because mapping resource might refer to custom types. CONFIG_TIME_LOB_HANDLER_HOLDER.set(this.lobHandler); } try { // Set connection release mode "on_close" as default. // This was the case for Hibernate 3.0; Hibernate 3.1 changed // it to "auto" (i.e. "after_statement" or "after_transaction"). // However, for Spring's resource management (in particular for // HibernateTransactionManager), "on_close" is the better default. config.setProperty(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE.toString()); if (!isExposeTransactionAwareSessionFactory()) { // Not exposing a SessionFactory proxy with transaction-aware // getCurrentSession() method -> set Hibernate 3.1 CurrentSessionContext // implementation instead, providing the Spring-managed Session that way. // Can be overridden by a custom value for corresponding Hibernate property. config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "org.springframework.orm.hibernate3.SpringSessionContext"); } if (this.entityInterceptor != null) { // Set given entity interceptor at SessionFactory level. config.setInterceptor(this.entityInterceptor); } if (this.namingStrategy != null) { // Pass given naming strategy to Hibernate Configuration. config.setNamingStrategy(this.namingStrategy); } if (this.typeDefinitions != null) { // Register specified Hibernate type definitions. Mappings mappings = config.createMappings(); for (int i = 0; i < this.typeDefinitions.length; i++) { TypeDefinitionBean typeDef = this.typeDefinitions[i]; mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters()); } } if (this.filterDefinitions != null) { // Register specified Hibernate FilterDefinitions. for (int i = 0; i < this.filterDefinitions.length; i++) { config.addFilterDefinition(this.filterDefinitions[i]); } } if (this.configLocations != null) { for (int i = 0; i < this.configLocations.length; i++) { // Load Hibernate configuration from given location. config.configure(this.configLocations[i].getURL()); } } if (this.hibernateProperties != null) { // Add given Hibernate properties to Configuration. config.addProperties(this.hibernateProperties); } if (currentDataSource != null) { boolean actuallyTransactionAware = (this.useTransactionAwareDataSource || currentDataSource instanceof TransactionAwareDataSourceProxy); // Set Spring-provided DataSource as Hibernate ConnectionProvider. config.setProperty(Environment.CONNECTION_PROVIDER, actuallyTransactionAware ? TransactionAwareDataSourceConnectionProvider.class.getName() : RoutingLocalDataSourceConnectionProvider.class.getName()); } if (this.jtaTransactionManager != null) { // Set Spring-provided JTA TransactionManager as Hibernate property. config.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, LocalTransactionManagerLookup.class.getName()); } if (this.mappingLocations != null) { // Register given Hibernate mapping definitions, contained in resource files. for (int i = 0; i < this.mappingLocations.length; i++) { config.addInputStream(this.mappingLocations[i].getInputStream()); } } if (this.cacheableMappingLocations != null) { // Register given cacheable Hibernate mapping definitions, read from the file system. for (int i = 0; i < this.cacheableMappingLocations.length; i++) { config.addCacheableFile(this.cacheableMappingLocations[i].getFile()); } } if (this.mappingJarLocations != null) { // Register given Hibernate mapping definitions, contained in jar files. for (int i = 0; i < this.mappingJarLocations.length; i++) { Resource resource = this.mappingJarLocations[i]; config.addJar(resource.getFile()); } } if (this.mappingDirectoryLocations != null) { // Register all Hibernate mapping definitions in the given directories. for (int i = 0; i < this.mappingDirectoryLocations.length; i++) { File file = this.mappingDirectoryLocations[i].getFile(); if (!file.isDirectory()) { throw new IllegalArgumentException("Mapping directory location [" + this.mappingDirectoryLocations[i] + "] does not denote a directory"); } config.addDirectory(file); } } if (this.entityCacheStrategies != null) { // Register cache strategies for mapped entities. for (Enumeration<?> classNames = this.entityCacheStrategies.propertyNames(); classNames .hasMoreElements(); /* */) { String className = (String) classNames.nextElement(); String[] strategyAndRegion = StringUtils .commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className)); if (strategyAndRegion.length > 1) { config.setCacheConcurrencyStrategy(className, strategyAndRegion[0], strategyAndRegion[1]); } else if (strategyAndRegion.length > 0) { config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]); } } } if (this.collectionCacheStrategies != null) { // Register cache strategies for mapped collections. for (Enumeration<?> collRoles = this.collectionCacheStrategies.propertyNames(); collRoles .hasMoreElements(); /* */) { String collRole = (String) collRoles.nextElement(); String[] strategyAndRegion = StringUtils .commaDelimitedListToStringArray(this.collectionCacheStrategies.getProperty(collRole)); if (strategyAndRegion.length > 1) { config.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0], strategyAndRegion[1]); } else if (strategyAndRegion.length > 0) { config.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0]); } } } if (this.eventListeners != null) { // Register specified Hibernate event listeners. for (Map.Entry<?, ?> entry : this.eventListeners.entrySet()) { Assert.isTrue(entry.getKey() instanceof String, "Event listener key needs to be of type String"); String listenerType = (String) entry.getKey(); Object listenerObject = entry.getValue(); if (listenerObject instanceof Collection) { Collection<?> listeners = (Collection<?>) listenerObject; EventListeners listenerRegistry = config.getEventListeners(); Object[] listenerArray = (Object[]) Array .newInstance(listenerRegistry.getListenerClassFor(listenerType), listeners.size()); listenerArray = listeners.toArray(listenerArray); config.setListeners(listenerType, listenerArray); } else { config.setListener(listenerType, listenerObject); } } } // Perform custom post-processing in subclasses. postProcessConfiguration(config); // Build SessionFactory instance. logger.debug( "[RoutingLocalSessionFactoryBean::buildSessionFactory] Building new Hibernate SessionFactory."); this.configuration = config; SessionFactoryProxy sessionFactoryProxy = new SessionFactoryProxy( repositoryManager.getDefaultRepository().getId()); for (Repository repository : repositoryManager.getRepositories()) { logger.debug("[RoutingLocalSessionFactoryBean::buildSessionFactory] " + "Repository '" + repository.getId() + "' -- Building SessionFactory..."); RepositoryManager.setCurrentRepository(repository.getId()); sessionFactoryProxy.addSessionFactory(repository.getId(), newSessionFactory(config)); } RepositoryManager.setCurrentRepository(repositoryManager.getDefaultRepository().getId()); sf = sessionFactoryProxy; } finally { if (currentDataSource != null) { // Reset DataSource holder. CONFIG_TIME_DS_HOLDER.set(null); } if (this.jtaTransactionManager != null) { // Reset TransactionManager holder. CONFIG_TIME_TM_HOLDER.set(null); } if (this.lobHandler != null) { // Reset LobHandler holder. CONFIG_TIME_LOB_HANDLER_HOLDER.set(null); } } // Execute schema update if requested. if (this.schemaUpdate) { updateDatabaseSchema(); } return sf; }
From source file:org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.java
License:Open Source License
protected void initDataStore() { if (TRACER.isEnabled()) { TRACER.trace("Initializing Configuration"); //$NON-NLS-1$ }/*from w w w .j ava2 s. c om*/ InputStream in = null; try { PackageRegistryProvider.getInstance().setThreadPackageRegistry(getRepository().getPackageRegistry()); cdoDataStore = new CDODataStore(); hibernateAuditHandler = new HibernateAuditHandler(); hibernateAuditHandler.setCdoDataStore(cdoDataStore); hibernateAuditHandler.setHibernateStore(this); cdoDataStore.setResetConfigurationOnInitialization(false); cdoDataStore.setName("cdo"); cdoDataStore.setPackageRegistry(getRepository().getPackageRegistry()); cdoDataStore.getExtensionManager().registerExtension(EMFInterceptor.class.getName(), CDOInterceptor.class.getName()); cdoDataStore.getExtensionManager().registerExtension(AuditHandler.class.getName(), CDOAuditHandler.class.getName()); cdoDataStore.getExtensionManager().registerExtension(AuditProcessHandler.class.getName(), CDOAuditProcessHandler.class.getName()); // don't do any persistence xml mapping in this datastore // make a local copy as it is adapted in the next if-statement // and we want to keep the original one untouched, if not // subsequent test runs will fail as they use the same // properties object final Properties props = new Properties(); props.putAll(getProperties()); props.remove(PersistenceOptions.PERSISTENCE_XML); if (!props.containsKey(PersistenceOptions.HANDLE_UNSET_AS_NULL)) { props.setProperty(PersistenceOptions.HANDLE_UNSET_AS_NULL, "true"); } cdoDataStore.setDataStoreProperties(props); Configuration hibernateConfiguration = cdoDataStore.getConfiguration(); if (mappingProvider != null) { mappingProvider.setHibernateStore(this); mappingXml = mappingProvider.getMapping(); hibernateConfiguration.addXML(mappingXml); } if (TRACER.isEnabled()) { TRACER.trace("Adding resource.hbm.xml to configuration"); //$NON-NLS-1$ } in = OM.BUNDLE.getInputStream(RESOURCE_HBM_PATH); hibernateConfiguration.addInputStream(in); // hibernateConfiguration.setInterceptor(new CDOInterceptor()); hibernateConfiguration.setProperties(props); // prevent the drop on close because the sessionfactory is also closed when // new packages are written to the db, so only do a real drop at deactivate if (hibernateConfiguration.getProperty(Environment.HBM2DDL_AUTO) != null && hibernateConfiguration.getProperty(Environment.HBM2DDL_AUTO).startsWith(HBM2DLL_CREATE)) { doDropSchema = true; // note that the value create also re-creates the db and drops the old one hibernateConfiguration.setProperty(Environment.HBM2DDL_AUTO, HBM2DLL_UPDATE); cdoDataStore.getDataStoreProperties().setProperty(Environment.HBM2DDL_AUTO, HBM2DLL_UPDATE); } else { doDropSchema = false; } final List<EPackage> ePackages = new ArrayList<EPackage>(packageHandler.getEPackages()); // get rid of the system packages for (EPackage ePackage : packageHandler.getEPackages()) { if (CDOModelUtil.isSystemPackage(ePackage) && ePackage != EtypesPackage.eINSTANCE) { ePackages.remove(ePackage); } } // remove the persistence xml if no epackages as this won't work without // epackages if (ePackages.size() == 0 && props.getProperty(PersistenceOptions.PERSISTENCE_XML) != null) { cdoDataStore.getDataStoreProperties().remove(PersistenceOptions.PERSISTENCE_XML); } if (isAuditing()) { auditEPackages = createAuditEPackages(cdoDataStore); final String auditMapping = mapAuditingEPackages(cdoDataStore, auditEPackages); // System.err.println(auditMapping); hibernateConfiguration.addXML(auditMapping); cdoDataStore.setAuditing(true); } cdoDataStore.setEPackages(ePackages.toArray(new EPackage[0])); } catch (Exception ex) { throw WrappedException.wrap(ex); } finally { PackageRegistryProvider.getInstance().setThreadPackageRegistry(null); IOUtil.close(in); } }
From source file:org.ikasan.connector.basefiletransfer.DataAccessUtil.java
License:BSD License
/** * static accessor for singleton TransactionalResourceCommandDAO * //w ww.j a v a 2s . c o m * @return singleton instance of TransactionalResourceCommandDAO */ public static TransactionalResourceCommandDAO getTransactionalResourceCommandDAO() { if (transactionalResourceCommandDAO == null) { InputStream transactionalResourceCommandMappings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("TransactionalResourceCommand.hbm.xml"); InputStream xidImplMappings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("XidImpl.hbm.xml"); Configuration cfg = generateConfiguration(); cfg.setProperty(Environment.DATASOURCE, "java:/datasource/ikasan/ds"); cfg.addInputStream(transactionalResourceCommandMappings); cfg.addInputStream(xidImplMappings); transactionalResourceCommandDAO = new HibernateTransactionalResourceCommandDAO( cfg.buildSessionFactory()); } return transactionalResourceCommandDAO; }
From source file:org.olat.core.commons.persistence.OLATLocalSessionFactoryBean.java
License:Apache License
@Override protected void postProcessMappings(Configuration config) throws HibernateException { try {/*from w w w .ja v a 2s . c o m*/ 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); } }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.beans.AdditionalHibernateMappings.java
License:Educational Community License
public void processConfig(Configuration config) throws IOException, MappingException { for (int i = 0; i < this.mappingLocations.length; i++) { config.addInputStream(this.mappingLocations[i].getInputStream()); }//from w w w . ja v a 2 s .com }
From source file:org.sakaiproject.springframework.orm.hibernate.impl.AdditionalHibernateMappingsImpl.java
License:Educational Community License
public void processConfig(Configuration config) throws IOException, MappingException { for (int i = 0; i < this.mappingLocations.length; i++) { try {/* ww w. ja v a 2 s . c o m*/ logger.info("Loading hbm: " + mappingLocations[i]); if (config == null) { logger.warn("config is null!"); return; } config.addInputStream(this.mappingLocations[i].getInputStream()); } catch (MappingException me) { throw new MappingException("Failed to load " + this.mappingLocations[i], me); } } }