有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java遇到异常,没有绑定到线程的Hibernate会话。我正在使用spring mvc

package com.ibs.dao;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibs.entity.LoginEntity;
@Repository
public class LoginDaoImpl implements LoginDaoInterface {

@Autowired
SessionFactory sessionFactory;


public boolean validateLogin(LoginEntity loginEntity)
{

    String eid=loginEntity.getEid();
    LoginEntity log=(LoginEntity)sessionFactory.getCurrentSession().load(LoginEntity.class, eid);

    if(log.getPassword().equals(loginEntity.getPassword()))
    {
        return true;
    }
    else
    {
        return false;
    }


}

}

我的spring servlet配置看起来像

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns= .........
..........
    <context:annotation-config/>
    <context:component-scan base-package="com.ibs"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <!-- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> -->
    <property name="URL" value="jdbc:-Oracle:thin:@192.168.25.221:1521:xe"/>
    <property name="user" value="lit"/>
    <property name="password" value="lit"/>
</bean>

        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

    <property name="dataSource" ref="dataSource"/>

        <property name="annotatedClasses">
            <list>
                 <value>com.ibs.entity.LoginEntity</value>
            </list>
        </property>

    <property name="hibernateProperties">
         <ref local="hibernateProperties"/>
    </property>
</bean>
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

错误详细信息:

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:700)
    com.ibs.dao.LoginDaoImpl.validateLogin(LoginDaoImpl.java:20)

共 (0) 个答案