Problemas ao persisti classe usando spring + jpa

1 resposta
C

fala ae galera, blz!?

minha aplicação está rodando spring + jpa(toplink) eu consigo popular meu entity e ateh dar o insert, segundo o stacktrack to tomcat, segue abaixo

[TopLink Fine]: Connection(19057119)–INSERT INTO TB_FORMULARIO (CPF, EMAIL, NOME, TELEFONE) VALUES (?, ?, ?, ?)
bind => [[CPF removido], , CARLOS, ]

só que qdo eu faço um select na base(usando mysql 5.0)
select * from tb_funcionario
aparece que o meu id foi populado com a chave auto_increment
mas todos os outros campos estão em branco :roll: :frowning:

meu spring-config-dao.xml está da seguinte maneira…

<?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:tx=“http://www.springframework.org/schema/tx
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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd”>

&lt;jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ufscar"/&gt;

&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
	&lt;property name="persistenceUnitName" value="posgraduacao"/&gt;
	&lt;property name="dataSource" ref="dataSource"/&gt;
	&lt;property name="loadTimeWeaver"&gt;
	  &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt;
	&lt;/property&gt;
	
	&lt;property name="jpaVendorAdapter"&gt;
		&lt;bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"&gt;
			&lt;property name="databasePlatform"
					value="oracle.toplink.essentials.platform.database.SQLAnyWherePlatform"/&gt;
			&lt;property name="generateDdl" value="false"/&gt;
			&lt;property name="showSql" value="true" /&gt;
		&lt;/bean&gt;
	&lt;/property&gt;
	
&lt;/bean&gt;

&lt;tx:annotation-driven/&gt;

&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
	&lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
&lt;/bean&gt;

&lt;!-- This makes Spring perform the magic @PersistenceContext/@PersitenceUnit injection --&gt;
&lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;

&lt;bean id="daoFormulario" class="br.ufscar.dc.posgraduacao.model.dao.toplink.FormularioDAOImpl" /&gt;

</beans>

tb tenho o spring-config-service.xml, segue abaixo

<?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:tx=“http://www.springframework.org/schema/tx
xsi:schemaLocation=“http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd”>

<bean id=“delegateFormulario”

class=“br.ufscar.dc.posgraduacao.delegate.FormularioDelegate”>

<property name=“formularioFacade”>

<ref local=“facadeFormulario”/>

</property>

</bean>
<bean id=“facadeFormulario”

class=“br.ufscar.dc.posgraduacao.facade.impl.FormularioFacadeImpl”>

<property name=“formularioDao”>

<ref bean=“daoFormulario”/>

</property>

</bean>

<!-- =========================================== Transacionals definitions -->

<!-- Ler mais sobre isso -->
<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>
<tx:attributes>
<tx:method name=“cadastrar”/>
<tx:method name=“update”/>
<tx:method name=“delete”/>
<tx:method name=“procurar*” read-only=“true”/>
<tx:method name=“listar” read-only=“true”/>
</tx:attributes>
</tx:advice>

</beans>

aonde defini minhas transações…

to achando q o spring naum tah pegando o EntityTransactionsaction do EntityManager e naum está fazendo o commit()

alguem poderia me ajudar!?

desde já agradeço!! :smiley:

1 Resposta

C

galera, descobri o pq de naum estar gravando no banco,
por algum motivo mto estranho, qdo minha aplicação chama o comando para listar todos dados da tabela tb_formulario, o toplink tah dano um update na tabela e setando valores em branco para os campos :confused:

[TopLink Fine]: Connection(32545329)–UPDATE TB_FORMULARIO SET CPF = ?, NOME = ? WHERE (ID = ?)
bind => [, , 22]

agora fikei mais confuso do q tudo :confused:

Criado 29 de novembro de 2006
Ultima resposta 29 de nov. de 2006
Respostas 1
Participantes 1