0 Replies Latest reply on Feb 10, 2006 6:52 PM by Horacio de Oro

    Exception:

    Horacio de Oro Newbie

      Hi!
      I get "org.hibernate.HibernateException: Unable to locate current JTA transaction" when trying to get the curretn hibernate session.
      See the logs:

      [STDOUT] ctx.lookup("java:/hibernate/TesisSessionFactory"): org.hibernate.impl.SessionFactoryImpl@153d2ae
      [STDOUT] ctx.lookup("UserTransaction")org.jboss.tm.usertx.client.ServerVMClientUserTransaction@1744dbf


      And when executing:

      session = HibernateContext.getSession("java:/hibernate/TesisSessionFactory");

      or
      session = factory.getCurrentSession();

      I get:

      20:14:04,473 ERROR [Home$Enhance_11] Hibernate genero un error
      org.hibernate.HibernateException: Unable to locate current JTA transaction
      at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
      at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:507)
      at org.jboss.hibernate.session.HibernateContext.getSession(HibernateContext.java:94)

      But if I execute:
      session = factory.getCurrentSession();

      I get a session and then I can lookup, update, insert and delete data.

      Using the jmx-console, and listing the JNDI tree I get this items (related to transactions):

      java: Namespace
      +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
      +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
      +- TransactionManager (class: org.jboss.tm.TxManager)

      Global JNDI Namespace
      +- UserTransactionSessionFactory (proxy: $Proxy37 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
      +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)

      While the app is loading I get this logs:

      20:20:11,345 INFO [NamingHelper] JNDI InitialContext properties:{}
      20:20:11,355 INFO [DatasourceConnectionProvider] Using datasource: java:PostgresDSTesis
      20:20:11,370 INFO [SettingsFactory] RDBMS: PostgreSQL, version: 8.0.6
      20:20:11,371 INFO [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 404)
      20:20:11,371 INFO [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
      20:20:11,371 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
      20:20:11,372 INFO [NamingHelper] JNDI InitialContext properties:{}
      20:20:11,372 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      20:20:11,373 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      20:20:11,373 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      20:20:11,373 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      20:20:11,373 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
      20:20:11,373 INFO [SettingsFactory] Automatic session close at end of transaction: enabled
      20:20:11,373 INFO [SettingsFactory] JDBC batch size: 15
      20:20:11,374 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
      20:20:11,374 INFO [SettingsFactory] Scrollable result sets: enabled
      20:20:11,374 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      20:20:11,374 INFO [SettingsFactory] Connection release mode: after_statement
      20:20:11,374 INFO [SettingsFactory] Default batch fetch size: 1
      20:20:11,374 INFO [SettingsFactory] Generate SQL with comments: disabled
      20:20:11,375 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      20:20:11,375 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      20:20:11,375 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      20:20:11,375 INFO [SettingsFactory] Query language substitutions: {}
      20:20:11,376 INFO [SettingsFactory] Second-level cache: enabled
      20:20:11,376 INFO [SettingsFactory] Query cache: disabled
      20:20:11,376 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
      20:20:11,376 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      20:20:11,376 INFO [SettingsFactory] Structured second-level cache entries: disabled
      20:20:11,376 INFO [SettingsFactory] Statistics: disabled
      20:20:11,376 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      20:20:11,376 INFO [SettingsFactory] Default entity-mode: pojo
      20:20:11,379 INFO [SessionFactoryImpl] building session factory
      20:20:11,945 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      20:20:11,946 INFO [NamingHelper] JNDI InitialContext properties:{}
      20:20:11,948 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/TesisSessionFactory]


      I'm deploying hibernate with a .har file. The hibernate-service.xml has:



      java:PostgresDSTesis
      org.hibernate.dialect.PostgreSQLDialect
      java:/hibernate/TesisSessionFactory
      org.hibernate.cache.HashtableCacheProvider
      yes



      and the datasource definition file has:

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
      <local-tx-datasource>
       <jndi-name>PostgresDSTesis</jndi-name>
       <connection-url>jdbc:postgresql://127.0.0.1:5432/tesis8</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>xxxx</user-name>
       <password>xxxx</password>
       <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
       <metadata>
       <type-mapping>PostgreSQL 7.2</type-mapping>
       </metadata>
      </local-tx-datasource>
      </datasources>


      In the WEB-INF/lib I've NO jar related to transactions nor hibernate.
      I've this problem with both jboss-4.0.3SP1 and jboss-4.0.4RC1.

      What I want is to share the same transaction within the same httprequest,
      and make work with JBoss something like Spring's "OpenSessionInView".


      What am I doing wrong?

      Thanks in advance!
      Horacio