Ae pessoal,
Estou tentando utilizar o hibernate numa aplicação web usando JTA. Para isso estou usando junto ao tomcat o jotm que eh um gerenciador de transações. O problema eh q por algum motivo, ele não está realizando o commit no banco.. olhando o log de inicialização do hibernate eu verifico q ele n está encontrando o gerenciador de transações. Eu sei q provavelmente eh alguma besteira na configuração, mas ateh agora n encontrei a resposta ne net.. espero q alguem possa me ajudar.. abaixo estão meus arquivos de configuração:
arquivo web.xml:
[quote]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>sisgea</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>servletteste</servlet-name>
<servlet-class>br.cefetrn.sisgea.servlet.ServletTeste</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servletteste</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>filtroHibernate</filter-name>
<filter-class>br.cefetrn.sisgea.persistencia.hibernate.util.FiltroHibernate</filter-class>
</filter>
<filter-mapping>
<filter-name>filtroHibernate</filter-name>
<servlet-name>servletteste</servlet-name>
</filter-mapping>
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
jdbc/SisgeaDB
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
</web-app>
[/quote]
[quote]<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- <property name="hibernate.connection.datasource">cc</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="TransactionStrategy">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="TransactionManagerLookupStrategy">
net.sf.hibernate.transaction.JOTMTransactionManagerLookup
</property>
<property name="FlushBeforeCompletionEnabled">true</property>
<property name="AutoCloseSessionEnabled">true</property> -->
<!-- properties -->
<property name="connection.datasource">java:/comp/env/jdbc/SisgeaDB</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="TransactionManagerLookupStrategy">
org.hibernate.transaction.JOTMTransactionManagerLookup
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<!-- <property name="hbm2ddl.auto">create</property> -->
<!-- Mostra o código sql gerado -->
<property name="show_sql">true</property>
<!-- adiciona comentários ao codigo sql gerado -->
<property name="hibernate.use_sql_comments">true</property>
<!-- -->
<property name="hibernate.generate_statistics">true</property>
<!--
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property> Condiguração do c3p0 -->
<mapping resource="Curso.hbm.xml"/>
<mapping resource="Disciplina.hbm.xml"/>
<mapping resource="Turma.hbm.xml"/>
<mapping resource="Pessoa.hbm.xml"/>
<mapping resource="Aluno.hbm.xml"/>
<mapping resource="Professor.hbm.xml"/>
<mapping resource="Endereco.hbm.xml"/>
</session-factory>
</hibernate-configuration>[/quote]
arquivo de contexto.xml:
[quote]<?xml version='1.0' encoding='utf-8'?>
<Context docBase="C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\webapps\sisgea.war" path="/sisgea" reloadable="true" >
<Resource name="jdbc/SisgeaDB" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SisgeaDB">
<parameter>
<name>factory</name>
<value>org.objectweb.jndi.DataSourceFactory</value>
</parameter>
<!-- configured by default for PostgreSQL, just change the values
to set it for your database
-->
<parameter><name>username</name><value>postgres</value></parameter>
<parameter><name>password</name><value>postgres</value></parameter>
<parameter><name>driverClassName</name>
<value>org.postgresql.Driver</value></parameter>
<parameter><name>url</name>
<value>jdbc:postgresql://localhost:5432/testepersistencia</value></parameter>
</ResourceParams>
<Resource name="UserTransaction" auth="Container"
type="javax.transaction.UserTransaction"/>
<ResourceParams name="UserTransaction">
<parameter>
<name>factory</name>
<value>org.objectweb.jotm.UserTransactionFactory</value>
</parameter>
<parameter>
<name>jotm.timeout</name>
<value>60</value>
</parameter>
</ResourceParams>
</Context>
[/quote]
trecho de codigo que faz o insert no banco:
[quote]FabricaDAO fabrica = FabricaDAO.getFabrica(null);
DAO dao = fabrica.criarDAOGenerico();
try{
System.out.println("Iniciando a transacao 2");
UserTransaction tx = (UserTransaction)new InitialContext().lookup("java:comp/env/UserTransaction");
tx.begin();
dao.inserir(objeto);
tx.commit();
System.out.println("parece q concluiu com sucesso");
retorno = true;
}catch(Exception e){
e.printStackTrace();
}[/quote]
Agradeço muito qq ajuda, principalmente pq meu prazo tah acabando :P.. hehehehhe, bem qq coisa eh soh falar..