javascript
java lazy loading_java – Spring,@Transactional和Hibernate Lazy Loading
Hibernate最近推出了提取配置文件(除了性能調(diào)優(yōu)之外)是解決這類問題的理想選擇.它允許您(在運(yùn)行時(shí))在不同的加載和初始化策略之間進(jìn)行選擇.
編輯(添加了關(guān)于如何使用攔截器設(shè)置抓取配置文件的部分):
開始之前:檢查抓取的個(gè)人資料實(shí)際上是否適合您.我沒有自己使用它們,看到他們目前僅限于加入提取.在浪費(fèi)時(shí)間實(shí)施和接線攔截器之前,請(qǐng)嘗試手動(dòng)設(shè)置抓取配置文件,看到它實(shí)際上可以解決您的問題.
public class FetchProfileInterceptor implements MethodInterceptor {
private SessionFactory sessionFactory;
private String fetchProfile;
... setters ...
public Object invoke(MethodInvocation invocation) throws Throwable {
Session s = sessionFactory.openSession(); // The transaction interceptor has already opened the session,so this returns it.
s.enableFetchProfile(fetchProfile);
try {
return invocation.proceed();
} finally {
s.disableFetchProfile(fetchProfile);
}
}
}
如果您是AOP的新手,建議先嘗試使用“舊”ProxyFactory方式(http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop-api .html#aop-api-proxying-intf),因?yàn)樗菀桌斫馑侨绾喂ぷ鞯?以下是一些示例XML,讓您開始:
...
class="org.springframework.aop.framework.Proxyfactorybean">
existingTransactionInterceptorBeanName
fetchProfileInterceptor
總結(jié)
以上是生活随笔為你收集整理的java lazy loading_java – Spring,@Transactional和Hibernate Lazy Loading的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: settime java import_
- 下一篇: 3、SpringBoot整合MyBati