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.  [ 4 posts ] 
Author Message
 Post subject: SessionFactory fails when I use JTA
PostPosted: Sun Sep 03, 2006 5:31 pm 
Newbie

Joined: Sun Sep 03, 2006 4:55 pm
Posts: 3
Hibernate version:3.1.3

JBoss version:4.0.4.GA


I can't get Hibernate to work with JTA. I feel like i've tried everything and i certainly don't want to waste anyone's time but I don't know what else to do so I hope someone here can help.

All the Hibernate examples I've done work fine but as soon as I add the JTA properties to the hibernate.cfg.xml it fails to create the SessionFactory object. I've used the standard HibernateUtil.java class from the Hibernate tutorial to create the SessionFactory object.

As I said, all the examples work until i use jta.


hibernate.cfg.xml

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate?autoReconnect=true</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>


<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.jta.UserTransaction">javax.transaction.UserTransaction</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>


<!-- Using open source C3PO production level JDBC database connection pooling instead of default hibernate -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">10000</property>


<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup-->
<property name="hbm2ddl.auto">update</property>

<property name="hibernate.connection.pool_size">10</property>

<mapping resource="test/Basic.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Error output
SESSIONFACTORY STARTING
21:26:46,578 INFO [STDOUT] 21:26:46,578 INFO [Environment] Hibernate 3.1.3
21:26:46,593 INFO [STDOUT] 21:26:46,593 INFO [Environment] hibernate.properties not found
21:26:46,593 INFO [STDOUT] 21:26:46,593 INFO [Environment] using CGLIB reflection optimizer
21:26:46,593 INFO [STDOUT] 21:26:46,593 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
21:26:46,796 INFO [STDOUT] 21:26:46,796 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
21:26:46,796 INFO [STDOUT] 21:26:46,796 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
21:26:47,078 INFO [STDOUT] 21:26:47,078 INFO [Configuration] Reading mappings from resource: test/Basic.hbm.xml
21:26:47,250 INFO [STDOUT] 21:26:47,250 INFO [HbmBinder] Mapping class: test.Basic -> BASICS
21:26:47,312 INFO [STDOUT] 21:26:47,312 INFO [Configuration] Configured SessionFactory: null
21:26:47,484 INFO [STDOUT] 21:26:47,484 INFO [C3P0ConnectionProvider] C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/hibernate?autoReconnect=true
21:26:47,484 INFO [STDOUT] 21:26:47,484 INFO [C3P0ConnectionProvider] Connection properties: {user=root, password=****}
21:26:47,484 INFO [STDOUT] 21:26:47,484 INFO [C3P0ConnectionProvider] autocommit mode: false
21:26:47,546 INFO [STDOUT] 21:26:47,546 INFO [MLog] MLog clients using log4j logging.
21:26:47,625 INFO [STDOUT] 21:26:47,625 INFO [C3P0Registry] Initializing c3p0-0.9.0 [built 11-July-2005 00:43:29 -0400; debug? true; trace: 10]
21:26:48,015 INFO [STDOUT] 21:26:48,015 INFO [PoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@77fcac [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@fa4704 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> fa4704, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxIdleTime -> 1800, maxPoolSize -> 50, maxStatements -> 10000, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@1601539 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1601539, jdbcUrl -> jdbc:mysql://localhost:3306/hibernate?autoReconnect=true, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> 77fcac, numHelperThreads -> 3 ]
21:26:48,296 INFO [STDOUT] 21:26:48,296 INFO [SettingsFactory] RDBMS: MySQL, version: 4.0.21-nt
21:26:48,296 INFO [STDOUT] 21:26:48,296 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.16-ga ( $Date: 2004/09/30 07:35:03 $, $Revision: 1.27.2.44 $ )
21:26:48,390 INFO [STDOUT] 21:26:48,390 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLMyISAMDialect
21:26:48,421 INFO [STDOUT] 21:26:48,421 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
21:26:48,421 INFO [STDOUT] 21:26:48,421 INFO [NamingHelper] JNDI InitialContext properties:{}
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] JDBC batch size: 15
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] Scrollable result sets: enabled
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
21:26:48,437 INFO [STDOUT] 21:26:48,437 INFO [SettingsFactory] Connection release mode: auto
21:26:48,453 INFO [STDOUT] 21:26:48,453 INFO [SettingsFactory] Maximum outer join fetch depth: 2
21:26:48,453 INFO [STDOUT] 21:26:48,453 INFO [SettingsFactory] Default batch fetch size: 1
21:26:48,453 INFO [STDOUT] 21:26:48,453 INFO [SettingsFactory] Generate SQL with comments: disabled
21:26:48,453 INFO [STDOUT] 21:26:48,453 INFO [SettingsFactory] Order SQL updates by primary key: disabled
21:26:48,453 INFO [STDOUT] 21:26:48,453 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
21:26:48,468 INFO [STDOUT] 21:26:48,468 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
21:26:48,468 INFO [STDOUT] 21:26:48,468 INFO [SettingsFactory] Query language substitutions: {}
21:26:48,468 INFO [STDOUT] 21:26:48,468 INFO [SettingsFactory] Second-level cache: enabled
21:26:48,468 INFO [STDOUT] 21:26:48,468 INFO [SettingsFactory] Query cache: disabled
21:26:48,468 INFO [STDOUT] 21:26:48,468 INFO [SettingsFactory] Cache provider: org.hibernate.cache.NoCacheProvider
21:26:48,484 INFO [STDOUT] 21:26:48,484 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
21:26:48,484 INFO [STDOUT] 21:26:48,484 INFO [SettingsFactory] Structured second-level cache entries: disabled
21:26:48,500 INFO [STDOUT] 21:26:48,500 INFO [SettingsFactory] Echoing all SQL to stdout
21:26:48,500 INFO [STDOUT] 21:26:48,500 INFO [SettingsFactory] Statistics: disabled
21:26:48,500 INFO [STDOUT] 21:26:48,500 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
21:26:48,500 INFO [STDOUT] 21:26:48,500 INFO [SettingsFactory] Default entity-mode: pojo
21:26:48,562 INFO [STDOUT] 21:26:48,562 INFO [SessionFactoryImpl] building session factory
21:26:49,406 INFO [STDOUT] 21:26:49,406 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
21:26:49,406 INFO [STDOUT] 21:26:49,406 INFO [SchemaUpdate] Running hbm2ddl schema update
21:26:49,406 INFO [STDOUT] 21:26:49,406 INFO [SchemaUpdate] fetching database metadata
21:26:49,421 INFO [STDOUT] 21:26:49,421 INFO [SchemaUpdate] updating schema
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [TableMetadata] table found: hibernate.basics
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [TableMetadata] columns: [namezcol, basic_id]
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [TableMetadata] foreign keys: []
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [TableMetadata] indexes: [primary]
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [SchemaUpdate] schema update complete
21:26:49,468 INFO [STDOUT] 21:26:49,468 INFO [NamingHelper] JNDI InitialContext properties:{}
21:26:49,468 ERROR [STDERR] Initial SessionFactory creation failed. java.lang.ClassCastException



public class HibernateUtil
{
private static final SessionFactory SESSIONFACTORY;

static
{
try
{
SESSIONFACTORY = new Configuration().configure().buildSessionFactory();
}
catch(Exception ex)
{
System.err.println("Initial SessionFactory creation failed. " + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionfactory()
{
return SESSIONFACTORY;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 6:15 pm 
Newbie

Joined: Wed Apr 06, 2005 7:45 pm
Posts: 3
Location: Brasil/MG
Review the code:

Quote:
SESSIONFACTORY = new Configuration().configure().buildSessionFactory();


Remove the "new" word.


In Hibernate-cfg, try this:

Remove:

<property name="hibernate.jta.UserTransaction">javax.transaction.UserTransaction</property>

Here goes the name in JNDI for lookup the UserTransaction. The manager_lookup_class will resolve this propertie;


Alter:

<property name="current_session_context_class">jta</property>

About C3PO, I don't how it works with JTA.

I'm using JTA on Tomcat with JOTM and in the setup of datasources I have to configure the factory that will provide the connections:

Code:
<Resource name="jdbc/mydb" type="javax.sql.DataSource"
   factory="org.objectweb.jndi.DataSourceFactory"
       driverClassName="oracle.jdbc.driver.OracleDriver"
        url="jdbc:oracle:thin:@host:1521:db"
        username="user" password="pass" />



(Please, forget about my poor english...)

_________________
Regards,

Roberto BadarĂ³
MG/Brasil


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 3:51 pm 
Newbie

Joined: Sun Sep 03, 2006 4:55 pm
Posts: 3
Hey Roberto,

Your english is better than my portuguese.

I've made the changes to the hibernate.cfg.xml but i can't Instantiate a Sessionfactory object without using the new argument. So i can't write
Code:
SESSIONFACTORY = Configuration().configure().buildSessionFactory();
as it shows an error. Do you know another way of writing a sessionFactory

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 10:01 am 
Newbie

Joined: Wed Apr 06, 2005 7:45 pm
Posts: 3
Location: Brasil/MG
My fault! The "new" is necessary... First instantiating the Configuration class, then calling the methods... Sorry!

Well, print the statcTrace of the ClassCastException for a detailed message.

_________________
Regards,

Roberto BadarĂ³
MG/Brasil


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.