First of all, sorry for my English.
So, I'm working with JSF. Recently we decided to exclude service layer from our project, cause this layer in 80% of cases consist only of recalling the same named dao-methods (definelty, I know, that this way is "not true"). So, now we need to make our managed beans layer transactional, and here is the problem: I can make dao-layer transactional, but when I try to move this duty to managegbeans layer, I get an
org.hibernate.HibernateException: No Session found for current thread
Dao and managedbeans layers are in separated modules, so they have separated context.xml files. When i define tx:annotation-driven tag in dao's context.xml file, @Transactional annotations in classes in dao-module are "visible", but when I try to define this tag in managedbeans context.xml file, none of the @Transactional annotations (neiter the dao, nor the managedbeans) are visible, so i get an exception.
Any ideas, how I can correctly configure transactions?
applicationContext-dao.xml
<jee:jndi-lookup id="dataSource" jndi-name="java:/MSSQLDataSource"/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>com.exadel.ubs.rss.entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<context:component-scan base-package="com.exadel.ubs.rss.dao"/>
applicationContext-web.xml
<context:annotation-config />
//Just because of the service layer is not fully removed, de facto we are using this import only for imort dao-context
<import resource="classpath:/applicationContext-service.xml"/>
<context:component-scan base-package="com.exadel.ubs.rss"/>
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="false"/>
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
Context param and listeners in web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext-web.xml
classpath:/applicationContext-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.company.project.util.ServletContextListenerConfig</listener-class>
</listener>
ServletContextListenerConfig class:
public class ServletContextListenerConfig implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");
}
public void contextDestroyed(ServletContextEvent event) {
// NOOP
}
}
Thanks in advance!
No comments:
Post a Comment