Note that there are some explanatory texts on larger screens.

plurals
  1. PONo Hibernate Session bound to thread exception
    primarykey
    data
    text
    <p>I have Hibernate 3.6.0.Final and Spring 3.0.0.RELEASE</p> <p>I get "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"</p> <p>If I add the thread specification back in, I get "saveOrUpdate is not valid without active transaction"</p> <p>Any ideas?</p> <p>The spring-config.xml:</p> <pre><code>&lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.maxheapsize" /&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt; &lt;property name="url" value="jdbc:hsqldb:mem:jsf2demo"/&gt; &lt;property name="username" value="sa"/&gt; &lt;property name="password" value=""/&gt; &lt;/bean&gt; &lt;bean id="sampleSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource" ref="sampleDataSource"/&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;com.maxheapsize.jsf2demo.Book&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;!-- prop key="hibernate.connection.pool_size"&gt;0&lt;/prop--&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/prop&gt; &lt;!-- prop key="transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/prop&gt; &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop--&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="sampleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName"&gt; &lt;value&gt;org.hsqldb.jdbcDriver&lt;/value&gt; &lt;/property&gt; &lt;property name="url"&gt; &lt;value&gt; jdbc:hsqldb:file:/spring/db/springdb;SHUTDOWN=true &lt;/value&gt; &lt;/property&gt; &lt;property name="username" value="sa"/&gt; &lt;property name="password" value=""/&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sampleSessionFactory"/&gt; &lt;/bean&gt; &lt;bean id="daoTxTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; &lt;property name="transactionManager" ref="transactionManager"/&gt; &lt;property name="transactionAttributes"&gt; &lt;props&gt; &lt;prop key="create*"&gt; PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED &lt;/prop&gt; &lt;prop key="get*"&gt; PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED &lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"&gt; &lt;property name="sessionFactory" ref="sampleSessionFactory"/&gt; &lt;property name="singleSession" value="true"/&gt; &lt;/bean&gt; &lt;bean id="nameDao" parent="daoTxTemplate"&gt; &lt;property name="target"&gt; &lt;bean class="com.maxheapsize.dao.NameDao"&gt; &lt;property name="sessionFactory" ref="sampleSessionFactory"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>and the DAO:</p> <pre><code>public class NameDao { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public SessionFactory getSessionFactory() { return sessionFactory; } @Transactional @SuppressWarnings("unchecked") public List&lt;Name&gt; getAll() { Session session = this.sessionFactory.getCurrentSession(); List&lt;Name&gt; names = (List&lt;Name&gt;)session.createQuery("from Name").list(); return names; } //@Transactional(propagation= Propagation.REQUIRED, readOnly=false) @Transactional public void save(Name name){ Session session = this.sessionFactory.getCurrentSession(); session.saveOrUpdate(name); session.flush(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload