在一个Service调用另一个类中的方法,引起Hibernate session关闭:CmsService.java---------------------@Service("cmsService")
public class CmsService extends SystemService implements ICmsService {
public String getSplitButtonMenuBar(User user) { .... dropdownMenuItems[i] = MenuParser.getDropdownMenuItem(url,"container", item);---------------------MenuParser.java---------------------public class MenuParser extends AbstractParser { public static String getDropdownMenuItem(String url, String target,String item) {
... }---------------------
当运行至红色代码部分,引起[org.hibernate.impl.SessionFactoryImpl] - closing错误。
static 方法中,只是进行了字串处理,是一个工具类,不需要Session才是正常的。但Hibernate session从Service层调用这个工具类,Sesseion却自动关闭了。
什么原因呢?
public class CmsService extends SystemService implements ICmsService {
public String getSplitButtonMenuBar(User user) { .... dropdownMenuItems[i] = MenuParser.getDropdownMenuItem(url,"container", item);---------------------MenuParser.java---------------------public class MenuParser extends AbstractParser { public static String getDropdownMenuItem(String url, String target,String item) {
... }---------------------
当运行至红色代码部分,引起[org.hibernate.impl.SessionFactoryImpl] - closing错误。
static 方法中,只是进行了字串处理,是一个工具类,不需要Session才是正常的。但Hibernate session从Service层调用这个工具类,Sesseion却自动关闭了。
什么原因呢?
解决方案 »
- 无法加载 reportingServicesWMI.dll(sql server 2008安装时)
- Lucene 2.4.1 就搜一条信息!需要一秒!
- webwork 双层循环问题,急!!!!!!!!!
- 求应用了struts+spring+hibernate的比较标准的系统
- tomcat启动时有一个关于servlet.jar not loaded的报错信息,请帮忙看一下
- struts2配置文件中的重定向问题
- MM郁闷死了
- hibernate关联
- 请各位指点,我想学JAVA,不知从何做起,我很迷惘,求求大家了!!!
- (弱智问题,顺便散分)类变量占用的内存在什么时候释放?JFrame等在关闭后一定要调用dispose方法吗?如果不调用可以吗?
- 关于jfreechart生成每根柱状图添加链接 研究好久了 没实现 能帮忙一下吗
- PropertyPlaceholderConfigurer有没有办法把属性注入到类里?
如果是这样的话把这个service类加上@Transactional注释统一将这个类里的所有方法都纳入事务管理器管理
2.就是在调用这个静态方法,Hibernate Session就自动关闭了。
3.这个方法是在一个循环中实现的,访问了一个实体类Entity,Entity要进行Lazy loading一个父对象。
@Transactional才是声明将这个类纳入事务管理
...
for (int i = 0; i < menuList.size(); i++) {
System.out.println("i: " + i);
Menu o = menuList.get(i);
url = o.getMenuUrl();
item = o.getMenuNameCn();
dropdownMenuItems[i] = MenuParser.getDropdownMenuItem(url,"container", item);
}
... }实际上是在一个循环中调用这个静态类的一个方法,进行字串处理。
---------------
<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:aspectj-autoproxy expose-proxy="true"/>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="put*" propagation="REQUIRED" />
<tx:method name="use*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="count*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="list*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config expose-proxy="true">
<aop:pointcut id="txPointcut" expression="execution(* com.weaforce..service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
-------------------