Spring Transaction - Desktop Application [Resolvido]

1 resposta
Guilherme_Gomes

Pessoal,

Tenho uma aplicação desktop que usa Spring. No final do post coloquei meu spring-config.xml

O que acontece é que consigo fazer queries normalmente no banco de dados, mas na hora de dar um merge ou persist, não vai! Não sei como colocar a transação pra comitar sempre que esses métodos forem chamados!

Tenho as anotações @Transactional em todos os DAOs.
Algum pode dar uma ajuda?
Obrigado!

<?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:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

	<context:component-scan base-package="br.com" />

	<context:property-placeholder location="info.properties" />

	<bean id="dataSourceN3"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl" value="${db.n3.url}" />
		<property name="user" value="${db.n3.user}" />
		<property name="password" value="${db.n3.password}" />

		<property name="acquireIncrement" value="${acquireIncrement}" />
		<property name="idleConnectionTestPeriod" value="${idleConnectionTestPeriod}" />
		<property name="maxPoolSize" value="${maxPoolSize}" />
		<property name="maxStatements" value="${maxStatements}" />
		<property name="minPoolSize" value="${minPoolSize}" />
	</bean>

	<bean id="dataSourceN4"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl" value="${db.n4.url}" />
		<property name="user" value="${db.n4.user}" />
		<property name="password" value="${db.n4.password}" />

		<property name="acquireIncrement" value="${acquireIncrement}" />
		<property name="idleConnectionTestPeriod" value="${idleConnectionTestPeriod}" />
		<property name="maxPoolSize" value="${maxPoolSize}" />
		<property name="maxStatements" value="${maxStatements}" />
		<property name="minPoolSize" value="${minPoolSize}" />
	</bean>


	<bean id="entityManagerFactoryN3"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="dataSourceN3" />
		<property name="persistenceUnitName" value="emfN3"></property>
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLInnoDBDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">false</prop>

				<prop key="hibernate.connection.autoReconnect">true</prop>
				<prop key="hibernate.connection.autoReconnectForPools">true</prop>
				<prop key="hibernate.connection.is-connection-validation-required">true</prop>
				<prop key="hibernate.current_session_context_class">thread</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
			</props>
		</property>
		<property name="persistenceProvider">
			<bean class="org.hibernate.ejb.HibernatePersistence"></bean>
		</property>
	</bean>

	<bean id="entityManagerFactoryN4"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="dataSourceN4" />
		<property name="persistenceUnitName" value="emfN4"></property>
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLInnoDBDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">false</prop>

				<prop key="hibernate.connection.autoReconnect">true</prop>
				<prop key="hibernate.connection.autoReconnectForPools">true</prop>
				<prop key="hibernate.connection.is-connection-validation-required">true</prop>
				<prop key="hibernate.current_session_context_class">thread</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
			</props>
		</property>
		<property name="persistenceProvider">
			<bean class="org.hibernate.ejb.HibernatePersistence"></bean>
		</property>
	</bean>


	<bean id="txManagerN3"
		class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory"
			ref="entityManagerFactoryN3" />
		<property name="dataSource" ref="dataSourceN3" />
	</bean>
	<bean id="txManagerN4"
		class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory"
			ref="entityManagerFactoryN4" />
		<property name="dataSource" ref="dataSourceN4" />
	</bean>

	<tx:annotation-driven transaction-manager="txManagerN3"
		proxy-target-class="true" />
	<tx:annotation-driven transaction-manager="txManagerN4"
		proxy-target-class="true" />

</beans>

1 Resposta

Guilherme_Gomes

Resolvido usando Spring + AspectJ

Criado 11 de novembro de 2009
Ultima resposta 11 de nov. de 2009
Respostas 1
Participantes 1