Opensessioninviewfilter + HibernateTransactionManager

1 resposta
M

Galera, estou tentando implementar o pradrão Opensessioninviewfilter mais n estou conseguindo persistir os dados! Quando eu chamo o save da session ele não persiste os dados! ele não cria o transaction e assim não da o commit na session, é como se o transactionManager não estivesse habilitado. segue ai um pedaço do código.
AGRADEÇO A AJUDA :D

web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	version="2.4">

	<display-name>baseProjectFilter</display-name>

	<!--
		There are three means to configure Wickets configuration mode and they
		are tested in the order given. 1) A system property:
		-Dwicket.configuration 2) servlet specific <init-param> 3) context
		specific <context-param> The value might be either "development"
		(reloading when templates change) or "deployment". If no configuration
		is found, "development" is the default.
	-->

	<!--
		Informa ao Spring para procurar seu arquivo de configuracao no
		classpath.
	-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!--
		Instala o filtro spring-hibernate responsavel por executar o padrao de
		projeto OpenSessionInView.
	-->
	<filter>
		<filter-name>opensessioninview.wicket</filter-name>
		<filter-class>
			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>opensessioninview.wicket</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- Instala o filtro wicket. -->
	<filter>
		<filter-name>wicket.base</filter-name>
		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
		<init-param>
			<param-name>applicationFactoryClassName</param-name>
			<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
		</init-param>
		<init-param>
			<param-name>applicationBean</param-name>
			<param-value>wicketApplication</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>wicket.base</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!--
		Instala o servlet listener do spring para executar o padrao de projeto
		IOC (Inversion of Control).
	-->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<session-config>
		<session-timeout>60</session-timeout>
	</session-config>
</web-app>

applicationContext

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<context:component-scan base-package="br.com.baseProjectFilter" annotation-config="true"/>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="mappingResources">
			<list>
				<value>Usuario.hbm.xml</value>
			</list>
		</property>
		<property name="configLocation">
			<value>classpath:hibernate.cfg.xml</value>
		</property>
		<property name="eventListeners">
            <map>
                <entry key="merge">
                    <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
                </entry>
            </map>
        </property>
	</bean>

	<!-- transactionManager -->

	  <!-- Transaction support beans -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <tx:annotation-driven/>

	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="inserir" propagation="REQUIRED" />
			<tx:method name="remover" propagation="REQUIRED" />
			<tx:method name="editar" propagation="REQUIRED" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<aop:config>
		<aop:pointcut id="service"
			expression="execution (*
    br.com.baseProjectFilter.repositorio.DAO.imp.*.* (..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="service" />
	</aop:config>

	<bean id="wicketApplication" class="br.com.baseProjectFilter.WicketApplication"></bean>
	

</beans>

HIbernateGenericDAO

package br.com.baseProjectFilter.repositorio.infra;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.SessionFactoryUtils;

import br.com.baseProjectFilter.negocios.entidades.Entidade;
import br.com.baseProjectFilter.repositorio.filtro.IFiltro;

public abstract class HibernateGenericDAO<ENTIDADE extends Entidade, ID extends Serializable, FILTRO extends IFiltro<ENTIDADE>>
implements IGenericDAO<ENTIDADE, ID, FILTRO> {

	private Class<ENTIDADE> classe;

	private SessionFactory sessionFactory;

	public HibernateGenericDAO(Class<ENTIDADE> classe,
			SessionFactory sessionFactory) {
		this.classe = classe;
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings("unchecked")
	public ENTIDADE buscar(final ID id) {
		return (ENTIDADE) this.getSession().get(classe, id);
	}

	public void editar(final ENTIDADE obj) {
		this.getSession().update(obj);
	}

	public List<ENTIDADE> filtrar(final FILTRO filtro) {
		// TODO Implementar HibernateGenericDAO -> filtrar
		return null;
	}

	public Class<ENTIDADE> getClasse() {
		return classe;
	}

	public Session getSession() {
		return SessionFactoryUtils.getSession(sessionFactory, false);
	}

	public void inserir(ENTIDADE obj) {
		this.getSession().save(obj);
	}

	@SuppressWarnings("unchecked")
	public List<ENTIDADE> listar() {
		return this.getSession().createQuery("FROM " + classe.getName()).list();
	}

	public void remover(final ENTIDADE obj) {
		this.getSession().delete(obj);
	}

	public void setClasse(final Class<ENTIDADE> classe) {
		this.classe = classe;
	}

}

Alguma alma caridosa ai para me ajudar!! agradeço a ajuda :D

1 Resposta

M

uma coisa que eu reparei é que pareçe que ele n habilita esse transactionManager!

Criado 24 de março de 2011
Ultima resposta 28 de mar. de 2011
Respostas 1
Participantes 1