Atomikos Forum

JSF2 ViewScope/Spring/Hibernate getSessionFactory null problem

Hi,
I am using spring + hibernate + jsf + mysql + atomikos in my project. Herebelow the version details

Spring: 3.0.5
Hibernate : 3.6.0
JSF : 2.0 (myfaces 2.0.12)
Mysql: 5.1.38 (InnoDB table structure)
Atomikos: 3.8.0
Tomcat: 6.0.20

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 getSessionFactory() in my DAO.

Any help on this?

Herebelow my settings etc:

@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);
}

}

======

GenericDao icinde save methodu:

public void save(Entity entity){
    Session session = getSessionFactory().getCurrentSession().save(entity);
}

======
======

Spring'teki xml Configurasyon'um su sekilde:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="atomikosDataSourceBean" />
        </property>
        <property name="packagesToScan">
            <list>
                <value>com.company.txtest.entity</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.connection.characterEncoding">utf8</prop>
                <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop>
                  <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
                  <prop key="hibernate.current_session_context_class">jta</prop>
                  <prop key="hibernate.connection.release_mode">auto</prop>
            </props>
        </property>
    </bean>


  <bean id="atomikosDataSourceBean" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" init-method="init" destroy-method="close">
        <property name="uniqueResourceName"><value>NonXADBMS</value></property>
        <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
        <property name="url"><value>jdbc:mysql://localhost:3306/txtestdb?autoReconnect=true</value></property>
        <property name="user"><value>username</value></property>
        <property name="password"><value>password</value></property>
        <property name="minPoolSize"><value>1</value></property>
    </bean>

    <!-- Construct Atomikos UserTransactionManager, needed to configure Spring -->
    <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"  init-method="init" destroy-method="close">
        <!--  when close is called, should we force transactions to terminate or not? -->
        <property name="forceShutdown"><value>true</value></property>
    </bean>

    <!-- Also use Atomikos UserTransactionImp, needed to configure Spring  -->
    <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
        <property name="transactionTimeout"><value>300</value></property>
    </bean>

    <tx:annotation-driven/>

    <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager"><ref bean="atomikosTransactionManager"  /></property>
        <property name="userTransaction"><ref bean="atomikosUserTransaction"  /></property>
    </bean>

    <bean id="genericDaoHibernate" class="com.company.txtest.dao.hibernate.GenericDaoHibernate">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
Mehmet Cabuk Send private email
Sunday, September 16, 2012
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics