|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | import java.lang.reflect.Array;
|
21 |
| -import java.lang.reflect.Method; |
22 | 21 | import java.sql.Connection;
|
23 | 22 | import java.sql.SQLException;
|
24 | 23 | import java.sql.Statement;
|
25 | 24 | import java.util.Collection;
|
26 | 25 | import java.util.Enumeration;
|
27 | 26 | import java.util.Map;
|
28 | 27 | import java.util.Properties;
|
29 |
| - |
30 | 28 | import javax.sql.DataSource;
|
31 | 29 | import javax.transaction.TransactionManager;
|
32 | 30 |
|
|
37 | 35 | import org.hibernate.cache.RegionFactory;
|
38 | 36 | import org.hibernate.cfg.Configuration;
|
39 | 37 | import org.hibernate.cfg.Environment;
|
| 38 | +import org.hibernate.cfg.Mappings; |
40 | 39 | import org.hibernate.cfg.NamingStrategy;
|
41 | 40 | import org.hibernate.dialect.Dialect;
|
42 | 41 | import org.hibernate.engine.FilterDefinition;
|
43 | 42 | import org.hibernate.engine.SessionFactoryImplementor;
|
44 | 43 | import org.hibernate.event.EventListeners;
|
45 | 44 | import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
|
46 | 45 | import org.hibernate.transaction.JTATransactionFactory;
|
| 46 | + |
47 | 47 | import org.springframework.beans.BeanUtils;
|
48 | 48 | import org.springframework.beans.factory.BeanClassLoaderAware;
|
49 | 49 | import org.springframework.core.io.ClassPathResource;
|
|
53 | 53 | import org.springframework.jdbc.support.JdbcUtils;
|
54 | 54 | import org.springframework.jdbc.support.lob.LobHandler;
|
55 | 55 | import org.springframework.util.ClassUtils;
|
56 |
| -import org.springframework.util.ReflectionUtils; |
57 | 56 | import org.springframework.util.StringUtils;
|
58 | 57 |
|
59 | 58 | /**
|
|
89 | 88 | * {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
|
90 | 89 | * {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
|
91 | 90 | *
|
92 |
| - * <p><b>Requires Hibernate 3.2 or later; tested with 3.3, 3.5 and 3.6.</b> |
| 91 | + * <p><b>Requires Hibernate 3.6 or later.</b> |
93 | 92 | * Note that this factory will use "on_close" as default Hibernate connection
|
94 | 93 | * release mode, unless in the case of a "jtaTransactionManager" specified,
|
95 | 94 | * for the reason that this is appropriate for most Spring-based applications
|
@@ -583,15 +582,9 @@ protected SessionFactory buildSessionFactory() throws Exception {
|
583 | 582 |
|
584 | 583 | if (this.typeDefinitions != null) {
|
585 | 584 | // Register specified Hibernate type definitions.
|
586 |
| - // Use reflection for compatibility with both Hibernate 3.3 and 3.5: |
587 |
| - // the returned Mappings object changed from a class to an interface. |
588 |
| - Method createMappings = Configuration.class.getMethod("createMappings"); |
589 |
| - Method addTypeDef = createMappings.getReturnType().getMethod( |
590 |
| - "addTypeDef", String.class, String.class, Properties.class); |
591 |
| - Object mappings = ReflectionUtils.invokeMethod(createMappings, config); |
| 585 | + Mappings mappings = config.createMappings(); |
592 | 586 | for (TypeDefinitionBean typeDef : this.typeDefinitions) {
|
593 |
| - ReflectionUtils.invokeMethod(addTypeDef, mappings, |
594 |
| - typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters()); |
| 587 | + mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters()); |
595 | 588 | }
|
596 | 589 | }
|
597 | 590 |
|
@@ -628,8 +621,7 @@ else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) {
|
628 | 621 |
|
629 | 622 | if (this.cacheRegionFactory != null) {
|
630 | 623 | // Expose Spring-provided Hibernate RegionFactory.
|
631 |
| - config.setProperty(Environment.CACHE_REGION_FACTORY, |
632 |
| - "org.springframework.orm.hibernate3.LocalRegionFactoryProxy"); |
| 624 | + config.setProperty(Environment.CACHE_REGION_FACTORY, LocalRegionFactoryProxy.class.getName()); |
633 | 625 | }
|
634 | 626 |
|
635 | 627 | if (this.mappingResources != null) {
|
@@ -685,12 +677,7 @@ else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) {
|
685 | 677 | String[] strategyAndRegion =
|
686 | 678 | StringUtils.commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className));
|
687 | 679 | if (strategyAndRegion.length > 1) {
|
688 |
| - // method signature declares return type as Configuration on Hibernate 3.6 |
689 |
| - // but as void on Hibernate 3.3 and 3.5 |
690 |
| - Method setCacheConcurrencyStrategy = Configuration.class.getMethod( |
691 |
| - "setCacheConcurrencyStrategy", String.class, String.class, String.class); |
692 |
| - ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, config, |
693 |
| - className, strategyAndRegion[0], strategyAndRegion[1]); |
| 680 | + config.setCacheConcurrencyStrategy(className, strategyAndRegion[0], strategyAndRegion[1]); |
694 | 681 | }
|
695 | 682 | else if (strategyAndRegion.length > 0) {
|
696 | 683 | config.setCacheConcurrencyStrategy(className, strategyAndRegion[0]);
|
|
0 commit comments