|
1 | 1 | /* |
2 | | - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 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. |
|
16 | 16 |
|
17 | 17 | package org.springframework.orm.hibernate4; |
18 | 18 |
|
19 | | -import java.lang.reflect.Method; |
20 | 19 | import java.sql.Connection; |
21 | 20 | import javax.sql.DataSource; |
22 | 21 |
|
|
45 | 44 | import org.springframework.transaction.support.DefaultTransactionStatus; |
46 | 45 | import org.springframework.transaction.support.ResourceTransactionManager; |
47 | 46 | import org.springframework.transaction.support.TransactionSynchronizationManager; |
48 | | -import org.springframework.util.ClassUtils; |
49 | | -import org.springframework.util.ReflectionUtils; |
50 | 47 |
|
51 | 48 | /** |
52 | 49 | * {@link org.springframework.transaction.PlatformTransactionManager} |
|
105 | 102 | public class HibernateTransactionManager extends AbstractPlatformTransactionManager |
106 | 103 | implements ResourceTransactionManager, InitializingBean { |
107 | 104 |
|
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 | | - |
117 | 105 | private SessionFactory sessionFactory; |
118 | 106 |
|
119 | 107 | private DataSource dataSource; |
@@ -293,7 +281,7 @@ protected Object doGetTransaction() { |
293 | 281 | } |
294 | 282 | else if (this.hibernateManagedSession) { |
295 | 283 | try { |
296 | | - Session session = (Session) ReflectionUtils.invokeMethod(getCurrentSessionMethod, this.sessionFactory); |
| 284 | + Session session = this.sessionFactory.getCurrentSession(); |
297 | 285 | if (logger.isDebugEnabled()) { |
298 | 286 | logger.debug("Found Hibernate-managed Session [" + session + "] for Spring-managed transaction"); |
299 | 287 | } |
@@ -337,7 +325,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) { |
337 | 325 |
|
338 | 326 | try { |
339 | 327 | if (txObject.getSessionHolder() == null || txObject.getSessionHolder().isSynchronizedWithTransaction()) { |
340 | | - Session newSession = SessionFactoryUtils.openSession(getSessionFactory()); |
| 328 | + Session newSession = getSessionFactory().openSession(); |
341 | 329 | if (logger.isDebugEnabled()) { |
342 | 330 | logger.debug("Opened new Session [" + newSession + "] for Hibernate transaction"); |
343 | 331 | } |
|
0 commit comments