Announcement Announcement Module
Collapse
No announcement yet.
Exception getting a thread bound Hibernate session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception getting a thread bound Hibernate session

    Hi,

    I'm using Struts 2.x + Spring 2.5 with Hibernate 3+ and annotations for transaction demarcation (with AspectJ). I get the following Exception when trying to get a hibernate session.

    Code:
    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:544)
    ...
    The code for the repository and the domain object is:
    Code:
    @Repository("userRepository")
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public class UserRepositoryImpl implements UserRepository {
        @Autowired
        private SessionFactory sessionFactory;
    
        @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
        public void update(User user) {
            sessionFactory.getCurrentSession().update(user);
        }
    }
    
    @Configurable
    @Entity
    public class User {
       ...
    }
    I'm using AspectJ for transactions.
    Code:
    <tx:annotation-driven mode="aspectj"/>
    and the aspect itself is defined in META-INF/aop.xml
    Code:
    <aspectj>
    <!--
        <weaver
                options="-showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
    -->
        <weaver>
            <include within="com.example.model..*"/>
        </weaver>
        <aspects>
            <include within="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
            <include within="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
        </aspects>
    </aspectj>
    Any ideas?

  • #2
    Shouldn't you be using <context:load-time-weaver/> instead of <tx:annotation-driven/> or configure a javaagent to apply the aspects at load time?
    Last edited by Marten Deinum; Nov 29th, 2007, 03:18 PM.

    Comment


    • #3
      I am using <context:load-time-weaver/> as well to inject the domain objects with some services.

      Comment


      • #4
        Can you post the whole stacktrace?

        Comment

        Working...
        X