-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: JTA and Standalone environment
PostPosted: Mon Aug 15, 2005 5:32 pm 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
Help!

I've tried a bunch of things to get the below to work from a stand alone test case. I got most of my details from here:
http://www.hibernate.org/282.html
but I'm not sure how to setup the TransactionManager in a standalone environment - is this even possible? If not, anyone that is familiar with JBoss to tell me how to configure the TransactionManager in JBoss?

Thanks alot!

Mark


Hibernate version:
3.95

Name and version of the database you are using:
MySQL

Code:
      Configuration cfg = new Configuration()
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect") 
    .setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver")
    .setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/taxelerate")
    .setProperty("hibernate.connection.username", "ivan")
    .setProperty("hibernate.connection.password", "")
    .setProperty("hibernate.session_factory_name", "hibernate/SessionFactory")
    .setProperty("hibernate.show_sql", "true")
    .setProperty("hibernate.transaction.flush_before_completion","true")
      .setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory")
      .setProperty("hibernate.transaction.manager_lookup_class",
            "org.hibernate.transaction.JBossTransactionManagerLookup")
    ;


17:26:35,471 INFO [Environment] Hibernate 3.0.5
17:26:35,471 INFO [Environment] hibernate.properties not found
17:26:35,502 INFO [Environment] using CGLIB reflection optimizer
17:26:35,502 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
17:26:35,705 INFO [Configuration] Mapping resource: com/westminster/taxelerate/beans/ProductBean.hbm.xml
17:26:36,236 INFO [HbmBinder] Mapping class: com.westminster.taxelerate.beans.ProductBean -> tx_product
17:26:36,299 INFO [Configuration] Mapping resource: com/westminster/taxelerate/beans/ItemBean.hbm.xml
17:26:36,408 INFO [HbmBinder] Mapping class: com.westminster.taxelerate.beans.ItemBean -> tx_item
17:26:36,627 INFO [Configuration] Mapping resource: com/westminster/taxelerate/beans/AccountBean.hbm.xml
17:26:36,690 INFO [HbmBinder] Mapping class: com.westminster.taxelerate.beans.AccountBean -> tx_account
17:26:36,690 INFO [Configuration] processing extends queue
17:26:36,690 INFO [Configuration] processing collection mappings
17:26:36,690 INFO [HbmBinder] Mapping collection: com.westminster.taxelerate.beans.AccountBean.items -> tx_item
17:26:36,705 INFO [Configuration] processing association property references
17:26:36,705 INFO [Configuration] processing foreign key constraints
17:26:36,768 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
17:26:36,768 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
17:26:36,768 INFO [DriverManagerConnectionProvider] autocommit mode: false
17:26:36,783 INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/taxelerate
17:26:36,783 INFO [DriverManagerConnectionProvider] connection properties: {user=ivan, password=}
17:26:37,361 INFO [SettingsFactory] RDBMS: MySQL, version: 4.1.7-max-log
17:26:37,361 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.14-production ( $Date: 2004/04/24 15:49:43 $, $Revision: 1.27.2.39 $ )
17:26:37,424 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
17:26:37,440 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
17:26:37,440 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
17:26:37,455 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
17:26:37,455 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
17:26:37,455 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
17:26:37,455 INFO [SettingsFactory] JDBC batch size: 15
17:26:37,455 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
17:26:37,455 INFO [SettingsFactory] Scrollable result sets: enabled
17:26:37,455 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
17:26:37,455 INFO [SettingsFactory] Connection release mode: null
17:26:37,471 INFO [SettingsFactory] Maximum outer join fetch depth: 2
17:26:37,471 INFO [SettingsFactory] Default batch fetch size: 1
17:26:37,471 INFO [SettingsFactory] Generate SQL with comments: disabled
17:26:37,471 INFO [SettingsFactory] Order SQL updates by primary key: disabled
17:26:37,471 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
17:26:37,486 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
17:26:37,486 INFO [SettingsFactory] Query language substitutions: {}
17:26:37,486 INFO [SettingsFactory] Second-level cache: enabled
17:26:37,486 INFO [SettingsFactory] Query cache: disabled
17:26:37,486 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
17:26:37,502 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
17:26:37,502 INFO [SettingsFactory] Structured second-level cache entries: disabled
17:26:37,518 INFO [SettingsFactory] Echoing all SQL to stdout
17:26:37,518 INFO [SettingsFactory] Statistics: disabled
17:26:37,518 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
17:26:37,533 INFO [SettingsFactory] Default entity-mode: pojo
17:26:37,861 INFO [SessionFactoryImpl] building session factory
17:26:37,908 WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Mark/workspace/Taxelerate/implementation/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
17:26:38,908 WARN [CacheFactory] read-only cache configured for mutable class: com.westminster.taxelerate.beans.ProductBean
17:26:38,908 WARN [EhCacheProvider] Could not find configuration [com.westminster.taxelerate.beans.ProductBean]; using defaults.
17:26:39,158 INFO [SessionFactoryObjectFactory] Factory name: hibernate/SessionFactory
17:26:39,174 INFO [NamingHelper] JNDI InitialContext properties:{}
17:26:39,440 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: hibernate/SessionFactory
17:26:39,440 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
17:26:39,440 INFO [NamingHelper] JNDI InitialContext properties:{}
Exception in thread "main" org.hibernate.HibernateException: Could not locate TransactionManager
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:270)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at com.westminster.taxelerate.account.AccountDao.main(AccountDao.java:51)
Caused by: javax.naming.NameNotFoundException: TransactionManager not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:544)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
... 3 more


Top
 Profile  
 
 Post subject: Do you need to span transaction?
PostPosted: Mon Aug 15, 2005 6:51 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Do you need to span transaction across multiple databases or other transactional resources?
If not, then you do not need XA transaction manager, org.hibernate.transaction.JDBCTransactionFactory will do.
http://www.hibernate.org/hib_docs/v3/re ... onstrategy

If you do need XA and want to work standalone then you may check this article on implementing that in Spring:
http://www.onjava.com/lpt/a/5854

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 9:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can use JOTM which is a standalone TM
You can also give a try to JBoss Embeddable container which allows you to embed, Hibernate Entity Manager and the EJB3 mecanism in your standalone application, it contains the TM (this product is alpha release).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 8:52 am 
Newbie

Joined: Wed Jan 21, 2004 10:09 am
Posts: 13
kgignatyev - Thanks for the response. As you can see from my properties, I'm using a org.hibernate.transaction.JDBCTransactionFactory, which is part of the problem :)

emmanuel - Thanks for the response and info. I looked at JOTM, and it will do what I would like, however it does so in a slightly different way. I was hoping to leave my standalone code identical to the JTA environment code AND looking like this:

Session session = factory.getCurrentSession();

JOTM doesn't quite work this way. I don't really want to use the embeddable container, and can't use Spring JTA on this project. I guess I'm outta luck eh? I didn't realize that having standalone and JTA type transactions were such a problem...

Thanks,

Mark


Top
 Profile  
 
 Post subject: CGLib
PostPosted: Tue Aug 16, 2005 10:58 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Actually you can:
Simply create factory for you DAO classes( CGLib lib based that returns enhanced versions of your classes).

Essence of the idea: every [public,declared, etc] method of you DAO class gets wrapped in your code that makes sure that ThreadLocal environment has session and properly finishes session and transaction.
Transaction and Session get propagated to any calls from within the first method in the DAO.
I have used this approach in the production for couple of years already.

More on the approach on my site:
http://kgionline.com/articles/aop_1/aop1.jsp

And this is quite performant:
http://kgionline.com/presentations/aop_ ... index.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: forgot to say
PostPosted: Tue Aug 16, 2005 11:00 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Forgot to say:
CGLib comes as a part of Hibernate dependencies, so my approach will not introduce anything extra into your project.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.