Robsonvnt 24 de ago. de 2009
edvaldo.santiago 24 de ago. de 2009
:oops:
Realizei alteração e mesmo assim não funcionou.
Valeu. :oops:
Robsonvnt 25 de ago. de 2009
qual banco de dados esta usando?
e qual tipo de generated vc esta usando para o Id
IDENTITY, AUTO qual?
edvaldo.santiago 25 de ago. de 2009
Boa tarde Robsonvnt
Então, eu rescrevi toda a parte do DAO usando a classe JpaDaoSupport e utilizando o controle de transação do Spring.
É claro, usei as suas dicas e aí sim funcionou.
applicationJpaContext.xml
& lt ;? xml version = "1.0" encoding = "UTF-8" ? & gt ;
& lt ; 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"
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" & gt ;
& lt ; bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" destroy - method = "close" & gt ;
& lt ; property name = "driverClassName" value = "com.mysql.jdbc.Driver" /& gt ;
& lt ; property name = "url" value = "jdbc:mysql://localhost/dbcontrole" /& gt ;
& lt ; property name = "username" value = "root" /& gt ;
& lt ; property name = "password" value = "" /& gt ;
& lt ; / bean & gt ;
& lt ; bean id = "entityManagerFactory" class = "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" & gt ;
& lt ; property name = "dataSource" ref = "dataSource" /& gt ;
& lt ; property name = "jpaVendorAdapter" & gt ;
& lt ; bean
class = "org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" & gt ;
& lt ; property name = "database" value = "MYSQL" /& gt ;
& lt ; property name = "showSql" value = "true" /& gt ;
& lt ; / bean & gt ;
& lt ; / property & gt ;
& lt ; / bean & gt ;
& lt ; bean id = "transactionManager" class = "org.springframework.orm.jpa.JpaTransactionManager" & gt ;
& lt ; property name = "entityManagerFactory" ref = "entityManagerFactory" & gt ; & lt ; / property & gt ;
& lt ; / bean & gt ;
& lt ; tx : annotation - driven mode = "proxy" /& gt ;
& lt ; context : annotation - config /& gt ;
& lt ; bean id = "inicialDao" class = "com.br.dao.impl.InicialDaoImpl" & gt ;
& lt ; property name = "entityManagerFactory" ref = "entityManagerFactory" & gt ; & lt ; / property & gt ;
& lt ; / bean & gt ;
& lt ; bean id = "facadeInicial" class = "com.br.facade.impl.FacadeInicialImpl" & gt ;
& lt ; property name = "inicialDao" ref = "inicialDao" & gt ; & lt ; / property & gt ;
& lt ; / bean & gt ;
& lt ; / beans & gt ;
Dao Generico
package com.br.dao ;
import java.util.List ;
import org.springframework.orm.jpa.support.JpaDaoSupport ;
import org.springframework.transaction.annotation.Transactional ;
@Transactional
public abstract class DaoAbstratct & lt ; T extends Object & gt ; extends JpaDaoSupport {
public void deletarJPA ( T t , Integer id ){
T tt = ( T ) pesquisarJPA ( t , id );
getJpaTemplate (). remove ( tt );
getJpaTemplate (). flush ();
}
public void updateJPA ( T t ){
getJpaTemplate (). merge ( t );
getJpaTemplate (). flush ();
}
public void inserirJPA ( T t ){
getJpaTemplate (). persist ( t );
getJpaTemplate (). flush ();
}
@SuppressWarnings ( "unchecked" )
@Transactional ( readOnly = true )
public T pesquisarJPA ( T t , Integer id ) {
return ( T ) getJpaTemplate (). find ( t . getClass (), id );
}
@SuppressWarnings ( "unchecked" )
@Transactional ( readOnly = true )
public List & lt ; T & gt ; listaGeralJPA ( Class & lt ; T & gt ; clazz ) {
return ( List & lt ; T & gt ;) getJpaTemplate (). find ( "from " + clazz . getName ());
}
}
Novamente eu agradeço atenção.
Valeu mesmo… Muito obrigado
Fui.