日期:2014-05-19  浏览次数:20602 次

struts2 spring3.2 hibernate4.1.9 整合No Session found for current thread
我就像做个shh 存储输入的信息到数据库然后显示succss   新人 对事务还是不太明白
网上说的方法也加了 实在是不会弄了 求大神指点




求助 下面发我源代码
applicationContext.xml

错误信息

dao层
javaee ssh hibernate

------解决方案--------------------

<bean id="transactionManager" 
class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory"></property>  
    </bean> 
    <tx:advice id = "txAdice" transaction-manager="transactionManager">
     <tx:attributes>
     <tx:method name="insert*" propagation="REQUIRED" />  
            <tx:method name="update*" propagation="REQUIRED" />  
            <tx:method name="delete*" propagation="REQUIRED" />  
            <tx:method name="get*" propagation="REQUIRED" read-only="true"/>  
            <tx:method name="query*" propagation="REQUIRED" read-only="true"/>  
            <tx:method name="*" propagation="REQUIRED" read-only="true" />
     </tx:attributes>
    </tx:advice>
    <aop:config>
     <aop:pointcut id="pointCut" expression="execution(* com.test..service.impl.*.*(..))" />
     <aop:advisor pointcut-ref="pointCut" advice-ref="txAdice"/>
    </aop:config>

------解决方案--------------------

/**
 * Copyright (C) 2012  http://blog.csdn.net/Just_szl
 * 
 * 修订历史记录:
 * 
 * Revision 1.0 2012-11-15 Geray  创建。
 * 
 */
package com.hibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;

/**
 * 
 * @author <a href="mailto:just_szl@hotmail.com"> Geray</a>
 * @version 1.0,2012-11-15 
 */
public class HibernateUtil {

private static SessionFactory sessionFactory;

private static Configuration configuration;

static
{
try {
configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();