* @throws IllegalArgumentException in case of illegal property values
* @throws HibernateException in case of Hibernate initialization errors
*/
public void afterPropertiesSet() throws IllegalArgumentException, HibernateException, IOException {
// Create Configuration instance.
Configuration config = newConfiguration();
if (this.dataSource != null) {
// Make given DataSource available for SessionFactory configuration.
configTimeDataSourceHolder.set(this.dataSource);
}
if (this.jtaTransactionManager != null) {
// Make Spring-provided JTA TransactionManager available.
configTimeTransactionManagerHolder.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.
configTimeLobHandlerHolder.set(this.lobHandler);
}
try {
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.configLocation != null) {
// Load Hibernate configuration from given location.
config.configure(this.configLocation.getURL());
}
if (this.hibernateProperties != null) {
// Add given Hibernate properties to Configuration.
config.addProperties(this.hibernateProperties);
}
if (this.dataSource != null) {
// Set Spring-provided DataSource as Hibernate property.
config.setProperty(Environment.CONNECTION_PROVIDER,
this.useTransactionAwareDataSource ?
TransactionAwareDataSourceConnectionProvider.class.getName() :
LocalDataSourceConnectionProvider.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.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);
}
}
// Perform custom post-processing in subclasses.
postProcessConfiguration(config);