Results 1 to 5 of 5

Thread: Spring 3.0.5 + Hibernate 3.6.0.Final - No Hibernate Session bound to thread

  1. #1
    Join Date
    Jan 2011
    Posts
    9

    Question Spring 3.0.5 + Hibernate 3.6.0.Final - No Hibernate Session bound to thread

    Hello all...

    I am trying to develop an application using Spring & Hibernate, but seem to be doing something wrong. I have tried searching the forum but have not found what I was missing... here is the whole story..

    1. I created a DAO with @Transactional Attribute as follows
    Code:
    @Transactional(readOnly = true, isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRES_NEW)
    	public List<E> findAll() {
    		return this.getSession().createQuery("from " + this.entityClass.getName()).list();
    	}
    where getSession is a helper method...
    Code:
    public Session getSession() {
    		if ((this.sessionFactory == null) || this.sessionFactory.isClosed()) {
    			throw new IllegalAccessError(
    					"Session Factory is either not initialized or is closed");
    		}
    		return this.sessionFactory.getCurrentSession();
    	}
    2. In my configuration... I have
    Code:
    <tx:annotation-driven transaction-manager="txManager"/>
        
        <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
        
        <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/bvdb"/>
        
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="packagesToScan" value="com.company.model" />
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
                  hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext
                    hibernate.show_sql=true
                </value>
            </property>
        </bean>
    It looks as though I am missing something really basic... Any suggestions?

  2. #2
    Join Date
    Jan 2011
    Posts
    9

    Post Thoughts anyone??

    Thoughts anyone??

  3. #3
    Join Date
    Jan 2011
    Posts
    9

    Thumbs up !!! Solved !!!

    Problem Solved...!!!!!

    The issue seems to be the location of the @Transactional annotation. I had the annotation placed in an abstract class which for some reason did not work. As soon as I moved the annotation to the child (concrete) class, everything worked as expected.

    It would be nice, if someone can explain why the annotation did not work in the generic abstract class.

  4. #4
    Join Date
    Nov 2010
    Posts
    3

  5. #5
    Join Date
    Jan 2011
    Posts
    9

    Thumbs up Thanks

    Quote Originally Posted by andrethiago View Post
    Thanks Andrethiago, it helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •