Problem com JPA+Hibernate+Spring update no lugar do select

6 respostas
W

OLá rapaziada, estou com um problema, meu projeto utiliza JPA com hibernate gerenciado pelo Spring,
as vezes ao dra um select ou mesmo editar um campo e cancelar, ao invés de seleciona e/ou cancelar o sistema dar um update no banco ou até salva um novo no mesmo,
alguém pode me dizer o pq disto ocorrer?

segue meus arquivos de configuração:

SPRing-config

<?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-3.0.xsd
		     http://www.springframework.org/schema/context
		     http://www.springframework.org/schema/context/spring-context-3.0.xsd
		     http://www.springframework.org/schema/tx
		     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
		     http://www.springframework.org/schema/aop 
		     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
	
	<tx:annotation-driven transaction-manager="txManager"/>
	
	<context:annotation-config />
	
	<context:component-scan base-package="br.com.nome" />
	
	<!-- Gerenciador de transacoes baseado em JPA -->
	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
	
	<bean id="persistentContextFactory"
      class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
	</bean>
	
	<!-- banco desenv -->
	<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="org.postgresql.Driver" />
		<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/banco" />
		<property name="user" value="124" />
		<property name="password" value="123" />
		<property name="initialPoolSize" value="20" />
 		<property name="minPoolSize" value="20" />
 		<property name="maxPoolSize" value="20" />
 		<property name="idleConnectionTestPeriod" value="500" /> 		
 		<property name="acquireIncrement" value="1" />
 		<property name="maxStatements" value="1000" /> 		 		
 		<property name="numHelperThreads" value="1" />
 		<property name="maxIdleTime" value="5"></property> 
	</bean>
	
	
	
	<!-- Fabrica de entity managers --> 
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="myDataSource" />
		<property name="persistenceUnitName" value="troqueiAki" />				
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
				<property name="showSql" value="true" />
 				<property name="generateDdl" value="true" />
 				<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />				
			</bean>
		</property>  		
	</bean>
	
	<bean id="myAspect" class="br.com.nome"/>
	
	<import resource="classpath:/META-INF/myview-spring-init.xml"/>
	
</beans>

persistence:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

	<persistence-unit name="nome" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>

<--classes-->

<exclude-unlisted-classes>false</exclude-unlisted-classes>

		<properties>
			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="false" />
			<property name="hibernate.max_fetch_depth" value="2" />
			<property name="hibernate.connection.pool_size" value="30" />
                        <property name="hibernate.c3p0.idle_test_period" value="40"></property>  
			<property name="hibernate.default_schema" value="public" />
			<property name="hibernate.c3p0.timeout" value="60" />
			<property name="hibernate.connection.release_mode" value="auto" />
			<property name="hibernate.generate_statistics" value="true"></property>
			<property name="hibernate.current_session_context_class" value="thread" />    
            <property name="hibernate.autocommit" value="false" /> 
            

		</properties>


	</persistence-unit>

</persistence>

se alguém poder ajudar

6 Respostas

R

Geralmente é problema de duplo submit.

Voce usa actions ? procura informacoes sobre o método saveToken.

W

não, não acho que seja duplo submit,…

R

bom, custa nada tentar ne ^^, mas se voce tem certeza que não é isso, eu por exemplo ja enfrentei este tipo de problema, e resolvi com saveToken.

Em todo caso, se puder detalhar, ou tentar ver o log do teu server e posta aqui pra vermos mais detalhes.

W

EU TESTEI A PARTE DE REQUISIÇÃO INUMERAS VEZES, SÓ PRA RELATAR, UTILIZO JSF 2

R

Entendi, é que la no titulo ta problem com JPA ^^, sorry!

W

rsrs, opa desculpa, tava caps look, sorry…
é que a unica coisa que vejo assim, é problema de configuração, mas analisando, eu não consigo encontrar, obrigado por sua contribuição.

Criado 16 de outubro de 2012
Ultima resposta 16 de out. de 2012
Respostas 6
Participantes 2