Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Hibernate Session Factory
Hibernate Session Factory [message #900813] Wed, 08 August 2012 15:09
Jens L. is currently offline Jens L.Friend
Messages: 1
Registered: August 2012
Junior Member
Hi there,

i am currently stuck with problem acquiring a valid hibernate session in my bean:

The error:

Constructor threw exception; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)


My spring-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
    <bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql:db" />
        <property name="username" value="xxx" />
        <property name="password" value="xxx" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="ds" />
        <property name="annotatedClasses">
            <array>
                <value>com.test.CollectionType</value>
            </array>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="javax.persistence.validation.mode">NONE</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <constructor-arg name="sessionFactory" ref="sessionFactory" />
    </bean>
    
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

    <context:annotation-config/>
    <context:component-scan base-package="com.test"/>
    <tx:annotation-driven transaction-manager="transactionManager"/>


</beans>


My Simple Test-Bean:



@Repository
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class SimpleDao {
    
    SessionFactory sf;
    
    @Autowired
    public SimpleDao(SessionFactory sf) {
        this.sf = sf;
        demo();
    }
    
    public void demo() {
        Session session = sf.getCurrentSession();
        Query query = session.createSQLQuery("select * from customers").setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
        ....
    }

    
}


Maybe someone can shed some light on what the problem is.

Thanks in advance.

Best regards,
Jens
Previous Topic:Configure Virgo to identify Web Context correct path
Next Topic:Exceptions injecting reserved beans in Blueprint
Goto Forum:
  


Current Time: Mon Nov 24 03:06:31 GMT 2014

Powered by FUDForum. Page generated in 0.01672 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software