标题:s2sh框架出现多次查询错误
只看楼主
ffs1992
Rank: 2
等 级:论坛游民
威 望:1
帖 子:9
专家分:10
注 册:2015-8-28
结帖率:0
已结贴  问题点数:1 回复次数:4 
s2sh框架出现多次查询错误
第一次查询所有数据没问题,连着第二次按照id查询就报错.
Struts Problem Report

Struts has detected an unhandled exception:

Messages:   
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
File:    org/springframework/orm/hibernate3/SpringSessionContext.java
Line number:    63
Stacktraces

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
    org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
    com.ffs.dao.impl.BaseDaoImpl.getSession(BaseDaoImpl.java:34)
    com.ffs.dao.impl.BaseDaoImpl.findById(BaseDaoImpl.java:66)
    com.ffs.service.impl.CategoryServiceImpl.findAllbyid(CategoryServiceImpl.java:33)
    com.ffs.action.CategoryAction.findbyid(CategoryAction.java:57)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
搜索更多相关主题的帖子: creation thread number 
2015-09-04 20:39
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分:1 
第一次查询所有数据没问题,连着第二次按照id查询就报错
是sql语句处理问题?会不会获取的值空格什么的没用trim或者语法有问题?

剑栈风樯各苦辛,别时冰雪到时春
2015-09-04 22:07
ffs1992
Rank: 2
等 级:论坛游民
威 望:1
帖 子:9
专家分:10
注 册:2015-8-28
得分:0 
package com.ffs.dao.impl;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.ffs.dao.BaseDao;
import com.ffs.entitys.Categorys;
public class BaseDaoImpl<T> implements BaseDao<T>{
    private Class<T> entityClass;
   
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @SuppressWarnings("unchecked")
    public BaseDaoImpl() {
        entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }
   
    public Session getSession() {
        
        return sessionFactory.getCurrentSession();
    }
   
    public void save(T instance) {
        try {
            getSession().save(instance);
        } catch (RuntimeException re) {
            throw re;
        }
    }
   
    public void delete(T instance) {
        try {
            getSession().delete(instance);
        } catch (RuntimeException re) {
            throw re;
        }
    }
   
    public void update(T instance) {
        try {
            getSession().update(instance);
        } catch (RuntimeException re) {
            throw re;
        }
    }
   
    @SuppressWarnings("rawtypes")
    public Object findById(Class clazz, Integer id) {
        try {
            System.out.println("basedaol里面查东西");
            //Hibernate.initialize(District.class);
            Object o = getSession().get(clazz,id);
            System.out.println("basedaol里面查东西2"+((Categorys)o).getC_name());;
            return o;
        } catch (RuntimeException re) {
            throw re;
        }
    }
这是dao层的代码
2015-09-05 08:02
ffs1992
Rank: 2
等 级:论坛游民
威 望:1
帖 子:9
专家分:10
注 册:2015-8-28
得分:0 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.
    xmlns:xsi="http://www. xmlns:context="http://www.
    xmlns:aop="http://www. xmlns:tx="http://www.
    xmlns:p="http://www.
    xsi:schemaLocation="http://www.
           http://www.
           http://www.
           http://www.
           http://www.
           http://www.
           http://www.
            http://www.
    <!-- 扫描指定的包 -->
    <!--<context:component-scan base-package="dao,service"/> -->
    <bean id="dataSource" destroy-method="close"
        class="com.mchange.v2.
        <!--连接数据库的驱动类 -->
        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
        <!--连接数据库的url -->
        <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl" />
        <!--连接数据库的用户名 -->
        <property name="user" value="scott" />
        <!--连接数据库的密码 -->
        <property name="password" value="orcl" />
        <!--连接池的最大连接数 -->
        <property name="maxPoolSize" value="40" />
        <!--连接池的最小连接数 -->
        <property name="minPoolSize" value="1" />
        <!--初始化连接数 -->
        <property name="initialPoolSize" value="1" />
        <!--连接的最大空闲时间,超时的连接将被丢弃,单位:秒 -->
        <property name="maxIdleTime" value="60" />
        <!--没有连接可用时,等待连接的时间,单位:毫秒 -->
        <property name="checkoutTimeout" value="2000" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.provider_class">
                    org.hibernate.cache.EhCacheProvider
                </prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.connection.isolation">2</prop>
            </props>
        </property>
        <!-- mappingResource -->
        <property name="packagesToScan">
            <list>
                <value>com.ffs.entitys</value>
            </list>
        </property>
    </bean>
    <!-- 使用spring的aop配置,声明式事务管理 -->
    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
<!--     <tx:annotation-driven transaction-manager="transactionManager"/> -->
    <!-- 配置事务通知属性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!-- 定义事务传播属性 -->
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="edit*" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="new*" propagation="REQUIRED" />
            <tx:method name="set*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="change*" propagation="REQUIRED" />
            <tx:method name="get*" propagation="REQUIRED" read-only="true" />
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />
            <tx:method name="load*" propagation="REQUIRED" read-only="true" />
            <tx:method name="*" propagation="REQUIRED" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <!-- 配置事务切面 -->
    <!-- 事务边界 -->
    <aop:config>
        <aop:pointcut id="serviceOperation" expression="execution(* dao.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
    </aop:config>
   
     <bean id="baseDao" class="com.ffs.dao.impl.BaseDaoImpl" abstract="true">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
   
    <bean id="entryDao" class="com.ffs.dao.impl.EntryDaoImpl" parent="baseDao"></bean>
    <bean id="entryServiceDao" class="com.ffs.service.impl.EntryServiceImpl">
    <property name="entryDao" ref="entryDao"></property>
    </bean>
    <bean id="entryAction" class="com.ffs.action.EntryAction">
    <property name="entryServiceDao" ref="entryServiceDao"></property>
    </bean>
    <bean id="categoryDao" class="com.ffs.dao.impl.CategoryDaoImpl" parent="baseDao"></bean>
    <bean id="categoryServiceDao" class="com.ffs.service.impl.CategoryServiceImpl">
    <property name="categoryDao" ref="categoryDao"></property>
    </bean>
    <bean id="categoryAction" class="com.ffs.action.CategoryAction">
    <property name="categoryServiceDao" ref="categoryServiceDao"></property>
    <property name="entryServiceDao" ref="entryServiceDao"></property>
    </bean>
</beans>
这是spring的配置文件
2015-09-05 08:02
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
得分:1 
添加事务
2015-09-06 09:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-457007-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.423789 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved