Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wqh754186373
spring-framework
提交
0dfb617d
S
spring-framework
项目概览
wqh754186373
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0dfb617d
编写于
10月 20, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refer to correct openSession() method for Hibernate 4.0 (SPR-8776)
上级
de5a007e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
5 deletion
+48
-5
org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java
...re/src/main/java/org/springframework/util/ClassUtils.java
+22
-0
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/HibernateTransactionManager.java
...framework/orm/hibernate4/HibernateTransactionManager.java
+1
-1
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java
...gframework/orm/hibernate4/LocalSessionFactoryBuilder.java
+2
-2
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/SessionFactoryUtils.java
...g/springframework/orm/hibernate4/SessionFactoryUtils.java
+21
-0
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewFilter.java
...ework/orm/hibernate4/support/OpenSessionInViewFilter.java
+1
-1
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java
.../orm/hibernate4/support/OpenSessionInViewInterceptor.java
+1
-1
未找到文件。
org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java
浏览文件 @
0dfb617d
...
...
@@ -605,6 +605,28 @@ public abstract class ClassUtils {
return
(
getMethodIfAvailable
(
clazz
,
methodName
,
paramTypes
)
!=
null
);
}
/**
* Determine whether the given class has a method with the given signature,
* and return it if available (else throws an <code>IllegalStateException</code>).
* <p>Essentially translates <code>NoSuchMethodException</code> to <code>IllegalStateException</code>.
* @param clazz the clazz to analyze
* @param methodName the name of the method
* @param paramTypes the parameter types of the method
* @return the method (never <code>null</code>)
* @throws IllegalStateException if the method has not been found
* @see java.lang.Class#getMethod
*/
public
static
Method
getMethod
(
Class
<?>
clazz
,
String
methodName
,
Class
<?>...
paramTypes
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Assert
.
notNull
(
methodName
,
"Method name must not be null"
);
try
{
return
clazz
.
getMethod
(
methodName
,
paramTypes
);
}
catch
(
NoSuchMethodException
ex
)
{
throw
new
IllegalStateException
(
"Expected method not found: "
+
ex
);
}
}
/**
* Determine whether the given class has a method with the given signature,
* and return it if available (else return <code>null</code>).
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/HibernateTransactionManager.java
浏览文件 @
0dfb617d
...
...
@@ -325,7 +325,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
try
{
if
(
txObject
.
getSessionHolder
()
==
null
||
txObject
.
getSessionHolder
().
isSynchronizedWithTransaction
())
{
Session
newSession
=
getSessionFactory
().
openSession
(
);
Session
newSession
=
SessionFactoryUtils
.
openSession
(
getSessionFactory
()
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Opened new Session ["
+
newSession
+
"] for Hibernate transaction"
);
}
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java
浏览文件 @
0dfb617d
...
...
@@ -65,10 +65,10 @@ public class LocalSessionFactoryBuilder extends Configuration {
new
AnnotationTypeFilter
(
MappedSuperclass
.
class
,
false
)};
private
static
final
Method
addAnnotatedClassMethod
=
ClassUtils
.
getMethod
IfAvailable
(
Configuration
.
class
,
"addAnnotatedClass"
,
Class
.
class
);
ClassUtils
.
getMethod
(
Configuration
.
class
,
"addAnnotatedClass"
,
Class
.
class
);
private
static
final
Method
addPackageMethod
=
ClassUtils
.
getMethod
IfAvailable
(
Configuration
.
class
,
"addPackage"
,
String
.
class
);
ClassUtils
.
getMethod
(
Configuration
.
class
,
"addPackage"
,
String
.
class
);
private
final
ResourcePatternResolver
resourcePatternResolver
;
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/SessionFactoryUtils.java
浏览文件 @
0dfb617d
...
...
@@ -16,6 +16,7 @@
package
org.springframework.orm.hibernate4
;
import
java.lang.reflect.Method
;
import
javax.sql.DataSource
;
import
org.apache.commons.logging.Log
;
...
...
@@ -50,6 +51,8 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
import
org.springframework.dao.InvalidDataAccessApiUsageException
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
import
org.springframework.jdbc.datasource.DataSourceUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
/**
* Helper class featuring methods for Hibernate Session handling.
...
...
@@ -74,6 +77,13 @@ public abstract class SessionFactoryUtils {
public
static
final
int
SESSION_SYNCHRONIZATION_ORDER
=
DataSourceUtils
.
CONNECTION_SYNCHRONIZATION_ORDER
-
100
;
/**
* A Method handle for the <code>SessionFactory.openSession()</code> method.
* The return value differs between Hibernate 3.x and 4.x; for cross-compilation purposes,
* we have to use reflection here as long as we keep compiling against Hibernate 3.x jars.
*/
private
static
final
Method
openSessionMethod
=
ClassUtils
.
getMethod
(
SessionFactory
.
class
,
"openSession"
);
static
final
Log
logger
=
LogFactory
.
getLog
(
SessionFactoryUtils
.
class
);
...
...
@@ -91,6 +101,17 @@ public abstract class SessionFactoryUtils {
return
null
;
}
/**
* Obtain a new Session from the given SessionFactory.
* <p>Bridges between Hibernate signature differences.
* @param sessionFactory the SessionFactory to use
* @return the new Session
* @see org.hibernate.SessionFactory#openSession()
*/
public
static
Session
openSession
(
SessionFactory
sessionFactory
)
{
return
(
Session
)
ReflectionUtils
.
invokeMethod
(
openSessionMethod
,
sessionFactory
);
}
/**
* Perform actual closing of the Hibernate Session,
* catching and logging any cleanup exceptions thrown.
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewFilter.java
浏览文件 @
0dfb617d
...
...
@@ -168,7 +168,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
*/
protected
Session
openSession
(
SessionFactory
sessionFactory
)
throws
DataAccessResourceFailureException
{
try
{
Session
session
=
sessionFactory
.
openSession
(
);
Session
session
=
SessionFactoryUtils
.
openSession
(
sessionFactory
);
session
.
setFlushMode
(
FlushMode
.
MANUAL
);
return
session
;
}
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java
浏览文件 @
0dfb617d
...
...
@@ -154,7 +154,7 @@ public class OpenSessionInViewInterceptor implements WebRequestInterceptor {
*/
protected
Session
openSession
()
throws
DataAccessResourceFailureException
{
try
{
Session
session
=
getSessionFactory
().
openSession
(
);
Session
session
=
SessionFactoryUtils
.
openSession
(
getSessionFactory
()
);
session
.
setFlushMode
(
FlushMode
.
MANUAL
);
return
session
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录