Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF2 ViewScope/Spring/Hibernate getSessionFactory NULL Error
    primarykey
    data
    text
    <p>We are using spring + hibernate + jsf + mysql + atomikos in our project. Here below the version details:</p> <ul> <li>Spring: 3.0.5</li> <li>Hibernate : 3.6.0</li> <li>JSF : 2.0 (myfaces 2.0.12)</li> <li>Mysql: 5.1.38 (InnoDB table structure)</li> <li>Atomikos: 3.8.0</li> <li>Tomcat: 6.0.20</li> </ul> <p>When I use JSF2 ViewScope bean to use transactional service in service layer, it works fine for the first request. It rollsback when there is a problem, and saves the two entities into different table when there is no problem. However, if I do the second request on the same view, then I get null object if I call <code>getSessionFactory()</code> in my DAO. </p> <p>Any help on this?</p> <p>Here below are my settings etc:</p> <pre><code>@ManagedBean @ViewScoped public class TestPageBean { public String click(){ testService.saveTest(obj1, obj2); } } @Transactional public class TestService { @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void saveTest(Object1 obj1, Object2 obj2) { dao1.save(obj1); dao2.save(obj2); } } </code></pre> <p>GenericDao includes save method:</p> <pre><code>public void save(Entity entity){ Session session = getSessionFactory().getCurrentSession().save(entity); } </code></pre> <p>Here is xml configuration of Spring:</p> <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref bean="atomikosDataSourceBean" /&gt; &lt;/property&gt; &lt;property name="packagesToScan"&gt; &lt;list&gt; &lt;value&gt;com.company.txtest.entity&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;prop key="hibernate.connection.characterEncoding"&gt;utf8&lt;/prop&gt; &lt;prop key="hibernate.transaction.factory_class"&gt;com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory&lt;/prop&gt; &lt;prop key="hibernate.transaction.manager_lookup_class"&gt;com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup&lt;/prop&gt; &lt;prop key="hibernate.current_session_context_class"&gt;jta&lt;/prop&gt; &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="atomikosDataSourceBean" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" init-method="init" destroy-method="close"&gt; &lt;property name="uniqueResourceName"&gt;&lt;value&gt;NonXADBMS&lt;/value&gt;&lt;/property&gt; &lt;property name="driverClassName"&gt;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&lt;/property&gt; &lt;property name="url"&gt;&lt;value&gt;jdbc:mysql://localhost:3306/txtestdb?autoReconnect=true&lt;/value&gt;&lt;/property&gt; &lt;property name="user"&gt;&lt;value&gt;username&lt;/value&gt;&lt;/property&gt; &lt;property name="password"&gt;&lt;value&gt;password&lt;/value&gt;&lt;/property&gt; &lt;property name="minPoolSize"&gt;&lt;value&gt;1&lt;/value&gt;&lt;/property&gt; &lt;/bean&gt; &lt;!-- Construct Atomikos UserTransactionManager, needed to configure Spring --&gt; &lt;bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"&gt; &lt;!-- when close is called, should we force transactions to terminate or not? --&gt; &lt;property name="forceShutdown"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt; &lt;/bean&gt; &lt;!-- Also use Atomikos UserTransactionImp, needed to configure Spring --&gt; &lt;bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"&gt; &lt;property name="transactionTimeout"&gt;&lt;value&gt;300&lt;/value&gt;&lt;/property&gt; &lt;/bean&gt; &lt;tx:annotation-driven/&gt; &lt;!-- Configure the Spring framework to use JTA transactions from Atomikos --&gt; &lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt; &lt;property name="transactionManager"&gt;&lt;ref bean="atomikosTransactionManager" /&gt;&lt;/property&gt; &lt;property name="userTransaction"&gt;&lt;ref bean="atomikosUserTransaction" /&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="genericDaoHibernate" class="com.company.txtest.dao.hibernate.GenericDaoHibernate"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; </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