@Value和Hibernate问题
生活随笔
收集整理的這篇文章主要介紹了
@Value和Hibernate问题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
@Value和Could not obtain transaction-synchronized Session for current thread
1.說(shuō)明
@Value(“#{}”) 表示SpEl表達(dá)式通常用來(lái)獲取bean的屬性,或者調(diào)用bean的某個(gè)方法。當(dāng)然還有可以表示常量。
2.出現(xiàn)的問(wèn)題
Caused by: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current threadat org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)at tdh.dao.impl.UserHibernateDaoImpl.selectMc(UserHibernateDaoImpl.java:104)at tdh.dao.impl.UserHibernateDaoImpl$$FastClassBySpringCGLIB$$e2f2f267.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)at tdh.dao.impl.UserHibernateDaoImpl$$EnhancerBySpringCGLIB$$bcfb1afd.selectMc(<generated>)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:117)at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129)at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49)at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:347)at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:121)at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:262)at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161)... 66 more3.解決方法
@Value(“#{}”) 表示SpEl表達(dá)式通常用來(lái)獲取bean的屬性,或者調(diào)用bean的某個(gè)方法。當(dāng)然還有可以表示常量。靜態(tài)提前加載,那時(shí)候dao還沒(méi)加載事務(wù)管理,事務(wù)在service上,在dao方法上面加一個(gè)事務(wù)的注解就行了,或者調(diào)用service里面加了注解的方法。
@Transactional(transactionManager = "userHTransactionManager")總結(jié)
以上是生活随笔為你收集整理的@Value和Hibernate问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 简单Map缓存
- 下一篇: js里面拼接代码和使用ModelAndV