Problema com hibernate + tomcat + jotm

2 respostas
Ronualdo_Augusto

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]
hibernate.cfg.xml
[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..

2 Respostas

Ronualdo_Augusto

Sim… esqueci… talvez isso ajude tb…

00:05:27,171 INFO Environment:474 - Hibernate 3.1 rc2 00:05:27,218 INFO Environment:504 - hibernate.properties not found 00:05:27,218 INFO Environment:520 - using CGLIB reflection optimizer 00:05:27,234 INFO Environment:550 - using JDK 1.4 java.sql.Timestamp handling 00:05:27,578 INFO Configuration:1257 - configuring from resource: /hibernate.cfg.xml 00:05:27,578 INFO Configuration:1234 - Configuration resource: /hibernate.cfg.xml 00:05:27,984 INFO Configuration:460 - Reading mappings from resource: Curso.hbm.xml 00:05:28,343 INFO HbmBinder:266 - Mapping class: br.cefetrn.sisgea.dominio.Curso -> Curso 00:05:28,546 INFO Configuration:460 - Reading mappings from resource: Disciplina.hbm.xml 00:05:28,656 INFO HbmBinder:266 - Mapping class: br.cefetrn.sisgea.dominio.Disciplina -> Disciplina 00:05:29,000 INFO Configuration:460 - Reading mappings from resource: Turma.hbm.xml 00:05:29,093 INFO HbmBinder:266 - Mapping class: br.cefetrn.sisgea.dominio.Turma -> Turma 00:05:29,187 INFO HbmBinder:1310 - Mapping collection: br.cefetrn.sisgea.dominio.Turma.alunos -> Turma_has_Aluno 00:05:29,203 INFO Configuration:460 - Reading mappings from resource: Pessoa.hbm.xml 00:05:29,250 INFO HbmBinder:266 - Mapping class: br.cefetrn.sisgea.dominio.Pessoa -> Pessoa 00:05:29,296 INFO Configuration:460 - Reading mappings from resource: Aluno.hbm.xml 00:05:29,453 INFO HbmBinder:825 - Mapping joined-subclass: br.cefetrn.sisgea.dominio.Aluno -> Aluno 00:05:29,703 INFO HbmBinder:1310 - Mapping collection: br.cefetrn.sisgea.dominio.Aluno.turmas -> Turma_has_Aluno 00:05:29,703 INFO Configuration:460 - Reading mappings from resource: Professor.hbm.xml 00:05:29,781 INFO HbmBinder:825 - Mapping joined-subclass: br.cefetrn.sisgea.dominio.Professor -> Professor 00:05:29,796 INFO Configuration:460 - Reading mappings from resource: Endereco.hbm.xml 00:05:29,843 INFO HbmBinder:266 - Mapping class: br.cefetrn.sisgea.dominio.Endereco -> Endereco 00:05:29,843 INFO Configuration:1368 - Configured SessionFactory: null 00:05:29,843 INFO Configuration:1014 - processing extends queue 00:05:29,859 INFO Configuration:1018 - processing collection mappings 00:05:29,859 INFO HbmBinder:2233 - Mapping collection: br.cefetrn.sisgea.dominio.Curso.disciplinas -> Disciplina 00:05:29,859 INFO HbmBinder:2233 - Mapping collection: br.cefetrn.sisgea.dominio.Disciplina.turmas -> Turma 00:05:29,859 INFO HbmBinder:2233 - Mapping collection: br.cefetrn.sisgea.dominio.Professor.turmas -> Turma 00:05:29,875 INFO Configuration:1027 - processing association property references 00:05:29,875 INFO Configuration:1049 - processing foreign key constraints 00:05:29,953 INFO NamingHelper:26 - JNDI InitialContext properties:{} 00:05:30,359 INFO DatasourceConnectionProvider:61 - Using datasource: java:/comp/env/jdbc/SisgeaDB 00:05:30,812 INFO SettingsFactory:77 - RDBMS: PostgreSQL, version: 8.1.1 00:05:30,828 INFO SettingsFactory:78 - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 404) 00:05:30,953 INFO Dialect:100 - Using dialect: org.hibernate.dialect.PostgreSQLDialect 00:05:31,015 INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JTATransactionFactory 00:05:31,031 INFO NamingHelper:26 - JNDI InitialContext properties:{} 00:05:31,046 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 00:05:31,046 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled 00:05:31,046 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled 00:05:31,046 INFO SettingsFactory:136 - JDBC batch size: 15 00:05:31,046 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled 00:05:31,062 INFO SettingsFactory:144 - Scrollable result sets: enabled 00:05:31,062 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled 00:05:31,062 INFO SettingsFactory:160 - Connection release mode: auto 00:05:31,062 INFO SettingsFactory:187 - Default batch fetch size: 1 00:05:31,078 INFO SettingsFactory:191 - Generate SQL with comments: enabled 00:05:31,078 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled 00:05:31,078 INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 00:05:31,109 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory 00:05:31,109 INFO SettingsFactory:203 - Query language substitutions: {} 00:05:31,109 INFO SettingsFactory:209 - Second-level cache: enabled 00:05:31,109 INFO SettingsFactory:213 - Query cache: disabled 00:05:31,109 INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.EhCacheProvider 00:05:31,187 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled 00:05:31,187 INFO SettingsFactory:237 - Structured second-level cache entries: disabled 00:05:31,218 INFO SettingsFactory:257 - Echoing all SQL to stdout 00:05:31,218 INFO SettingsFactory:264 - Statistics: enabled 00:05:31,218 INFO SettingsFactory:268 - Deleted entity synthetic identifier rollback: disabled 00:05:31,218 INFO SettingsFactory:283 - Default entity-mode: POJO 00:05:31,718 INFO SessionFactoryImpl:155 - building session factory 00:05:31,750 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: file:/C:/Arquivos de programas/Apache Software Foundation/Tomcat 5.0/work/Catalina/localhost/sisgea/loader/ehcache-failsafe.xml 00:05:33,406 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 00:05:33,406 INFO SessionFactoryImpl:432 - Checking 1 named queries

Ronualdo_Augusto

Alguem ajuda ae… :P…

Criado 17 de junho de 2006
Ultima resposta 19 de jun. de 2006
Respostas 2
Participantes 1