TWO open Sessions

zl283936851 2010-05-12 12:16:07
在action里面调用了两次Service的方法,导致了 two open Session 这是为什么呢
一下是代码:
1.action里面的方法:

public String addPrSubtype() throws Exception{
DgProductType instance=this.iDgProductTypeService.findById(this.dgProductType.getPrTyId());
...
this.iDgProductTypeService.attachDirty(instance);
return "success";
}

2.service里面的方法
public class DgProductTypeService implements IDgProductTypeService {
...
public void attachDirty(DgProductType instance) {
// TODO Auto-generated method stub
this.iDgProductTypeDAO.attachDirty(instance);
}

public DgProductType findById(Integer id) {
// TODO Auto-generated method stub
DgProductType dgProductType =this.iDgProductTypeDAO.findById(id);
return dgProductType;
}


}


3.事务管理器
	<!-- 事务管理器配置 -->	
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor"
>
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定对满足哪些bean name的bean自动生成业务代理 -->
<property name="beanNames">
<!-- 下面是所有需要自动创建事务代理的bean-->
<list>
<value>productTypeService</value>
<value>dgUserService</value>
<value>dgUserTypeService</value>

</list>
<!-- 此处可增加其他需要自动创建事务代理的bean-->
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<!-- 此处可增加其他新的Interceptor -->
<value>transactionInterceptor</value>
</list>
</property>
</bean>

4.web.xml
  <!--*********** Filter************* -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config </param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts-user.xml,struts-product.xml</param-value>
</init-param>
</filter>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<!-- zh-cn encoding -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
com.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<!--<filter>
<filter-name>loginFilter</filter-name>
<filter-class>com.LoginFilter</filter-class>
</filter>

-->
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

...全文
64 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zl283936851 2010-07-28
  • 打赏
  • 举报
回复
对不起啊~最近回了下 学校~·没什么时间上 现在补上~见谅
Octer 2010-05-12
  • 打赏
  • 举报
回复
感觉像 你的事务是控制在service层
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定对满足哪些bean name的bean自动生成业务代理 -->
<property name="beanNames">
<!-- 下面是所有需要自动创建事务代理的bean-->
<list>
<value>productTypeService</value>
<value>dgUserService</value>
<value>dgUserTypeService</value>


</list>
<!-- 此处可增加其他需要自动创建事务代理的bean-->
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<!-- 此处可增加其他新的Interceptor -->
<value>transactionInterceptor</value>
</list>
</property>
</bean>
PDF版 Tomcat: The Definitive Guide, 2nd Edition By: Jason Brittain; Ian F. Darwin Publisher: O'Reilly Media, Inc. Pub. Date: October 23, 2007 Print ISBN-13: 978-0-596-10106-0 Print ISBN-10: 0-596-10106-6 Pages in Print Edition: 496 Overview: It takes a book as versatile as its subject to cover Apache Tomcat, the popular open source Servlet and JSP container and high performance web server. Tomcat: The Definitive Guide is a valuable reference for administrators and webmasters, a useful guide for programmers who want to use Tomcat as their web application server during development or in production, and an excellent introduction for anyone interested in Tomcat. Updated for the latest version of Tomcat, this new edition offers a complete guide to installing, configuring, maintaining and securing this servlet container. In fact, with such a wealth of new information, this is essentially a new book rather than a simple revision. You will find details for using Tomcat on all major platforms, including Windows, Linux, OS X, Solaris, and FreeBSD, along with specifics on Tomcat configuration files, and step-by-step advice for deploying and running web applications. This book offers complete information for: * Installation and startup procedures * * Configuring Tomcat-including realms, roles, users, servlet sessions, and JNDI resources including JDBC DataSources * * Deploying web applications-individual servlets and JSP pages, and web application archive files * * Tuning Tomcat to measure and improve performance * * Integrating Tomcat with Apache Web Server * * Securing Tomcat to keep online thugs at bay * * Tomcat configuration files-server.xml and web.xml, and more * * Debugging and Troubleshooting-diagnosing problems with Tomcat or a web application * * Compiling your own Tomcat, rather than using the pre-built release * * Running two or more Tomcat servlet containers in parallel * This book also offers an overview of the Tomcat open source project's community resources, including docs, mailing lists, and more. Community interest fueled a strong demand for a Tomcat guide from O'Reilly. The result clearly exceeds expectations.
Key Features Create efficient and secure embedded devices using Linux Minimize project costs by using open source tools and programs Explore each component technology in depth, using sample implementations as a guide Book Description Mastering Embedded Linux Programming takes you through the product cycle and gives you an in-depth description of the components and options that are available at each stage. You will begin by learning about toolchains, bootloaders, the Linux kernel, and how to configure a root filesystem to create a basic working device. You will then learn how to use the two most commonly used build systems, Buildroot and Yocto, to speed up and simplify the development process. Building on this solid base, the next section considers how to make best use of raw NAND/NOR flash memory and managed flash eMMC chips, including mechanisms for increasing the lifetime of the devices and to perform reliable in-field updates. Next, you need to consider what techniques are best suited to writing applications for your device. We will then see how functions are split between processes and the usage of POSIX threads, which have a big impact on the responsiveness and performance of the final device The closing sections look at the techniques available to developers for profiling and tracing applications and kernel code using perf and ftrace. What you will learn Understand the role of the Linux kernel and select an appropriate role for your application Use Buildroot and Yocto to create embedded Linux systems quickly and efficiently Create customized bootloaders using U-Boot Employ perf and ftrace to identify performance bottlenecks Understand device trees and make changes to accommodate new hardware on your device Write applications that interact with Linux device drivers Design and write multi-threaded applications using POSIX threads Measure real-time latencies and tune the Linux kernel to minimize them About the Author Chris Simmonds is a software consultant and trainer who lives in southern England. He has been using Linux in embedded systems since the late 1990s, during which he has worked on many interesting projects, including a stereoscopic camera, intelligent weighing scales, various set-top boxes and home routers, and even a large walking robot. He is a frequent presenter at open source and embedded conferences, including the Embedded Linux Conference, Embedded World, and the Android Builders' Summit. He has been conducting training courses and workshops in embedded Linux since 2002 and in embedded Android since 2010. He has delivered hundreds of sessions to many well-known companies. You can see some of his work on the "Inner Penguin" blog at www.2net.co.uk. Table of Contents Chapter 1: Starting Out Chapter 2: Learning About Toolchains Chapter 3: All About Bootloaders Chapter 4: Porting and Configuring the Kernel Chapter 5: Building a Root Filesystem Chapter 6: Selecting a Build System Chapter 7: Creating a Storage Strategy Chapter 8: Introducing Device Drivers Chapter 9: Starting up - The init Program Chapter 10: Learning About Processes and Threads Chapter 11: Managing Memory Chapter 12: Debugging with GDB Chapter 13: Profiling and Tracing Chapter 14: Real-time Programming

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧