0
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;
    }


}

}

My spring-servlet-config looks like

<?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>

Error details:

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)
5
  • Do you have some configuration part where you declare transaction manager? Commented Sep 12, 2014 at 5:37
  • Check this post - stackoverflow.com/questions/18608611/… Commented Sep 12, 2014 at 5:39
  • thanks, now i configured transaction manager. but a new error came up -> Error creating bean with name 'loginController': Injection of autowired dependencies failed; What may be the possible cause ?? Commented Sep 12, 2014 at 5:56
  • Sharat, update your question and add the changes that you did and complete stacktrace of the error. Commented Sep 12, 2014 at 6:39
  • Thanks. everything is alright now. Commented Sep 13, 2014 at 4:01

1 Answer 1

0

Change following line from LoginDaoImpl

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

To:

 LoginEntity log=(LoginEntity)sessionFactory.openSession().load(LoginEntity.class, eid);

Alternatively: add a property of key hibernate.current_session_context_class and value Thread in hibernate properties.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.