tags:

views:

53

answers:

1

What is this error about? "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here". My spring config file looks something like this.

<bean id="jndiDataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:/devDS</value>
    </property>
</bean>
<bean id="stsaDBFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="jndiDataSource" />
    <property name="annotatedClasses">
        <list>
            <value>xx.yy.zz.User</value>
            <value>xx.yy.UserResponse</value>

        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbmddl.auto">create</prop>
        </props>
    </property>
</bean>

<!-- ################################### Aspects ################################################## -->

<bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="stsaDBFactory" />
    </property>
</bean>

All the DAO test passes when i test them outside of the container using junit. When I deploy it in jBoss as a portal app,I get this exception. Also it works fine if i remove the portal specific configuration and make it a simple web app and deploy it on jboss.Any idea?

+1  A: 

You have defined a TransactionManager in your spring config but you are trying to execute a hibernate query in a method that is not transactional. Try adding @Transacational to your method or class.

Rob
Its just a select query. Do i have to add this annotation to all DAO methods?
chedine
It can be on the DAO method or on the service method or on either of the classes, but it has to be somewhere in the stack if you're using a TransactionManager or you will get the exception you encountered because you are trying to run a query outside of a transaction.
Rob
How come some are working without this annotation?
chedine
Possibly they are being run from a context where no TransactionManager has been defined?
Rob