我的是STRUTS2,SPRING,HIBERNATE3,结构是如下的层次: 
public class CommonServiceImpl extends HibernateDaoSupport implements 
CommonService { protected void delete(Object object) { 
getHibernateTemplate().delete(object); 
} .....这里调用gethibernateTemplate 
} 然后在service层的接口,这样搞: 
public interface IArticleService extends CommonService 
{ } 
而service层的接口实现则这样搞; 
public class ArticleServiceImpl extends CommonServiceImpl implements IArticleService{ //这里注入了dao 
private IArticleDao articleDao; }   DAO层的接口如下: 
public interface IArticleDao extends CommonService{ } DAO层的实现: 
public class ArticleDaoImpl extends CommonServiceImpl implements IArticleDao { } 在配置文件方面,我这样搞: 
在service-context.xml中: 
<bean id="articleService" parent="txProxyTemplate"> 
<property name="target"> 
<bean class="ArticleServiceImpl"> <property name="articleDao"> 
<ref bean="articleDao" /> 
</property> 
</bean> 
</property> </bean> 在dao-context.xml中 
<bean id="articleDao" parent="txProxyTemplate"> 
    <property name="target"> 
      <bean class="ArticleDaoImpl"> 
      <property name="sessionFactory"> 
<ref bean="sessionFactory" /> 
</property> 
      </bean> 
    </property> 
  </bean> 最后,是applicationContext.xml 
<bean id="transactionManager" 
class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
<property name="sessionFactory"> 
<ref local="sessionFactory" /> 
</property> 
</bean> <bean id="commonServiceImpl" 
class="com.trustel.service.CommonServiceImpl"> 
<property name="sessionFactory"> 
<ref local="sessionFactory" /> 
</property> </bean> <bean id="commonService" 
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
<property name="transactionManager"> 
<ref bean="transactionManager" /> 
</property> 
<property name="target"> 
<ref local="commonServiceImpl" /> 
</property> 
<property name="transactionAttributes"> 
<props> 
<prop key="*">PROPAGATION_REQUIRED</prop> 
</props> 
</property> 
</bean> <bean id="txProxyTemplate" abstract="true" 
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
<property name="proxyTargetClass"> 
<value>true</value> 
</property> 
<property name="transactionManager"> 
<ref bean="transactionManager" /> 
</property> 
<property name="transactionAttributes"> 
<props> 
<prop key="*"> 
PROPAGATION_REQUIRED 
</prop> </props> 
</property> 
</bean>   我原来的情景是,在action层中,我一般是先调用articleservce(就是调用service层)的,再通过service层调用DAO层,这个时候,spring应该会自动关闭session吧? 
   我现在的问题是,假如我在action层中,直接调用DAO层,不通过articleservice层,那么这个时候,hibernatedaosupport能自动关闭session么? 

解决方案 »

  1.   

    我上面的这个结构设计合理么,不知为何,很担心HIBERNATE,还是觉得SPRING JDBC好
      

  2.   

    不关service层的事吧
    看你自己怎么配置
      

  3.   

      为什么不把业务写在service层呢
       只要配置好了,就没问题的。
      

  4.   

     我现在就是S2SH 开发
      业务层放在service层,dao只做对数据库操作
       配事务在service层,这样会让人感觉层次很分明,代码读起来也不错。
      

  5.   

    我原来也是SERVICE层调用DAO层的,但想试下,直接调用DAO层是否快点
      

  6.   

    把 org.springframework 的日志级别调到最低的 DEBUG 级别,看一下日志输出你就知道是不是能关闭了。
      

  7.   

    LZ看这个
     一:如果通过HibernateDaoSupport来getSession  那么 这个session当一个方法结束的时候 就关闭了 
     二:如果通过HibenateDAOSupport 来getSessionFactory在opensession()那么就是   方法结束后不会关闭session需要自己手动的关闭 再看这个
    他是使用AOP在方法调用之前开启一个SESSION 结束之后关闭SESSION 小的不会SPRING 不过您要是通过SPRING去创建一个对象并且使用他的话 我想 他应该会自己关闭连接的
    不会SPRING的LV9乱盖漂过..
      

  8.   

    proxtool里的那个监控里,details:里的born就是表示可供使用的连接什么时候产生吧,我晚上10点多,看到born是22:10,last start那里是空的,这个时候应该是还没外来连接过来吧? 
    但我很快,都10点多了,很快就发现last start里有时间显示里,这个时候应该是有连接过来了吧?但业务专家分析,我们的系统,不大可能晚上也经常有连接过来的,我观察了周6,日,晚上也都是这个情况,不大符合逻辑,那个last start的含义其实是什么呢?