|
16 | 16 |
|
17 | 17 | package org.springframework.orm.hibernate4; |
18 | 18 |
|
| 19 | +import java.lang.reflect.Method; |
19 | 20 | import java.sql.Connection; |
20 | 21 | import javax.sql.DataSource; |
21 | 22 |
|
|
44 | 45 | import org.springframework.transaction.support.DefaultTransactionStatus; |
45 | 46 | import org.springframework.transaction.support.ResourceTransactionManager; |
46 | 47 | import org.springframework.transaction.support.TransactionSynchronizationManager; |
| 48 | +import org.springframework.util.ClassUtils; |
| 49 | +import org.springframework.util.ReflectionUtils; |
47 | 50 |
|
48 | 51 | /** |
49 | 52 | * {@link org.springframework.transaction.PlatformTransactionManager} |
|
102 | 105 | public class HibernateTransactionManager extends AbstractPlatformTransactionManager |
103 | 106 | implements ResourceTransactionManager, InitializingBean { |
104 | 107 |
|
| 108 | + /** |
| 109 | + * A Method handle for the <code>SessionFactory.getCurrentSession()</code> method. |
| 110 | + * The return value differs between Hibernate 3.x and 4.x; for cross-compilation purposes, |
| 111 | + * we have to use reflection here as long as we keep compiling against Hibernate 3.x jars. |
| 112 | + */ |
| 113 | + private static final Method getCurrentSessionMethod = |
| 114 | + ClassUtils.getMethod(SessionFactory.class, "getCurrentSession"); |
| 115 | + |
| 116 | + |
105 | 117 | private SessionFactory sessionFactory; |
106 | 118 |
|
107 | 119 | private DataSource dataSource; |
@@ -281,7 +293,7 @@ protected Object doGetTransaction() { |
281 | 293 | } |
282 | 294 | else if (this.hibernateManagedSession) { |
283 | 295 | try { |
284 | | - Session session = getSessionFactory().getCurrentSession(); |
| 296 | + Session session = (Session) ReflectionUtils.invokeMethod(getCurrentSessionMethod, this.sessionFactory); |
285 | 297 | if (logger.isDebugEnabled()) { |
286 | 298 | logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction"); |
287 | 299 | } |
|
0 commit comments