Hibernate: Could not bind factory to JNDI

Boa noite amigo,

Estou rachando minha cabeça para faezr um simples programa que utilize o Hibernate. Porem não estou conseguindo.
Seguem os arquivos:

hibernate.properties:

hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class = org.gjt.mm.mysql.Driver
hibernate.connection.url = jdbc:mysql://127.0.0.1:3306/hibernate
hibernate.connection.username = root
hibernate.connection.password = root

hibernate.cfg.xml:

<?xml version="1.0"?>

O erro:

30/05/2010 17:43:06 net.sf.hibernate.cfg.Environment
INFO: Hibernate 2.1.8
30/05/2010 17:43:06 net.sf.hibernate.cfg.Environment
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=root, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect , hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/hibernate, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver}
30/05/2010 17:43:06 net.sf.hibernate.cfg.Environment
INFO: using CGLIB reflection optimizer
30/05/2010 17:43:06 net.sf.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Amigo.hbm.xml
30/05/2010 17:43:06 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: teste
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Amigo.hbm.xml
30/05/2010 17:43:06 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
30/05/2010 17:43:06 net.sf.hibernate.cfg.Mappings addClass
WARNING: duplicate class mapping: Amigo
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: Amigo.hbm.xml
30/05/2010 17:43:06 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
30/05/2010 17:43:06 net.sf.hibernate.cfg.Mappings addClass
WARNING: duplicate class mapping: Amigo
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
WARNING: No dialect set - using GenericDialect: Dialect class not found: net.sf.hibernate.dialect.MySQLDialect
30/05/2010 17:43:06 net.sf.hibernate.dialect.Dialect
INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
30/05/2010 17:43:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
30/05/2010 17:43:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
30/05/2010 17:43:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://127.0.0.1:3306/hibernate
30/05/2010 17:43:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=root}
30/05/2010 17:43:06 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): true
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
30/05/2010 17:43:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
30/05/2010 17:43:06 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
30/05/2010 17:43:06 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/usuario/Workspace/Hibernate/lib/ehcache-1.5.0.jar!/ehcache-failsafe.xml
30/05/2010 17:43:06 net.sf.hibernate.impl.SessionFactoryImpl
INFO: building session factory
30/05/2010 17:43:06 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: teste
30/05/2010 17:43:06 net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
30/05/2010 17:43:06 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at net.sf.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at net.sf.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:172)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at AmigoDAO.(AmigoDAO.java:17)
at Principal.main(Principal.java:14)

Minha pergunta é: o que é esse JNDI? Esse negócio ai fica pedindo pedindo e pedindo, tá foda.
Até já procurei pra caramba na net sobre isso, mas nada efetivo.
Me ajudem por favor.

Para configurar o Hibernate vc deve usar apenas uma forma, as duas formas de configuração juntas não dá certo.

Por acaso você está utilizando o hibernate na versão 2??

A versão do Hibernate que estou utilizando é a 3.5.2 que baixei no site www.hibernate.org

Você usou apenas uma forma de configuração??

Sim, só essa com os arquivos hibernate.cfg.xml e hibernate.properties
Há alguma outra que posso tentar?

[quote=LucasRey]Sim, só essa com os arquivos hibernate.cfg.xml e hibernate.properties
Há alguma outra que posso tentar?[/quote]

Você deve usar apenas uma, ou usa o hibernate.cfg.xml ou usa o hibernate.properties, os dois não funciona

Então, é só colocar o conteudo dos dois em um só? Hummm.
Vou testar!

Ainda estou encontrando problemas, amigo.
Tá foda.

Então cara, meu hibernate.cfg.xml ficou assim:

<?xml version="1.0"?> org.gjt.mm.mysql.Driver jdbc:mysqld://localhost:3306/hibernate root root

5
20
1800
50
org.hibernate.dialect.MySQLDialect
false
true
net.sf.hibernate.transaction.JTATransactionFactory
java:comp/UserTransaction

Minha chamado ao factory na classe AmigoDAO ficou assim:

Configuration cfg = new Configuration();
this.factory = cfg.configure().buildSessionFactory();

Mas agora o erro é esse ENORME:

01/06/2010 21:21:48 net.sf.hibernate.cfg.Environment
INFO: Hibernate 2.1.8
01/06/2010 21:21:48 net.sf.hibernate.cfg.Environment
INFO: hibernate.properties not found
01/06/2010 21:21:48 net.sf.hibernate.cfg.Environment
INFO: using CGLIB reflection optimizer
01/06/2010 21:21:48 net.sf.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Amigo.hbm.xml
01/06/2010 21:21:48 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: java:hibernate/SessionFactory
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
01/06/2010 21:21:48 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
0 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
01/06/2010 21:21:48 net.sf.hibernate.cfg.SettingsFactory buildSettings
WARNING: No dialect set - using GenericDialect: Could not instantiate dialect class
01/06/2010 21:21:48 net.sf.hibernate.dialect.Dialect
INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
01/06/2010 21:21:48 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
01/06/2010 21:21:48 net.sf.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysqld://localhost:3306/hibernate
01/06/2010 21:21:48 net.sf.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=root, password=root}
01/06/2010 21:21:48 com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
01/06/2010 21:21:49 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
01/06/2010 21:21:49 net.sf.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
01/06/2010 21:21:49 net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
01/06/2010 21:21:49 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
01/06/2010 21:21:49 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
01/06/2010 21:21:49 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool… com.mchange.v2.c3p0.PoolBackedDataSource@a85bcf7b [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@108a3d4 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2rvxwl881w9kulm19bbxo6|193722c, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@b19a7f26 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2rvxwl881w9kulm19bbxo6|2ce908, jdbcUrl -> jdbc:mysqld://localhost:3306/hibernate, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2rvxwl881w9kulm19bbxo6|92bbba, numHelperThreads -> 3 ]
01/06/2010 21:22:09 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@15bdc50 – APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
01/06/2010 21:22:09 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@15bdc50 – APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@9e5c73 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@c791b9 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3020ad (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1b15692
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1aa9f99
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

01/06/2010 21:22:18 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3020ad – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:12
at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1172)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:803)
at AmigoDAO.(AmigoDAO.java:22)
at Principal.main(Principal.java:45)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
… 7 more
01/06/2010 21:22:18 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@c791b9 – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
01/06/2010 21:22:18 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@9e5c73 – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: false
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
01/06/2010 21:22:18 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
01/06/2010 21:22:18 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
01/06/2010 21:22:18 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/usuario/Workspace/Amigo/lib/ehcache-1.5.0.jar!/ehcache-failsafe.xml
01/06/2010 21:22:18 net.sf.hibernate.impl.SessionFactoryImpl
INFO: building session factory
01/06/2010 21:22:18 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: java:hibernate/SessionFactory
01/06/2010 21:22:18 net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
01/06/2010 21:22:18 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: Could not bind factory to JNDI
javax.naming.NamingException: scheme java not recognized
at org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:211)
at javax.naming.InitialContext.lookup(Unknown Source)
at net.sf.hibernate.util.NamingHelper.bind(NamingHelper.java:59)
at net.sf.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:172)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at AmigoDAO.(AmigoDAO.java:22)
at Principal.main(Principal.java:45)
01/06/2010 21:22:38 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1b15692 – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPerTaskAsynchronousRunner$TaskThread.run(ThreadPerTaskAsynchronousRunner.java:255)
01/06/2010 21:22:38 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: null
01/06/2010 21:22:38 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Connections could not be acquired from the underlying database!
01/06/2010 21:22:38 net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.exception.GenericJDBCException: Cannot open connection
at net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:80)
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:32
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3373)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3333)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:63)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:5
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:111)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:454)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at AmigoDAO.insert(AmigoDAO.java:31)
at Principal.main(Principal.java:46)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:12
at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:292)
… 14 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
… 17 more
01/06/2010 21:22:38 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1aa9f99 – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPerTaskAsynchronousRunner$TaskThread.run(ThreadPerTaskAsynchronousRunner.java:255)

Meu Amigo.hbm.xml continua o mesmo:

<?xml version="1.0" encoding="UTF-8"?>

Você configurou o sistema de transação do JTA??

faz um teste com esse hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!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.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>

    <mapping resource="Amigo.hbm.xml" />
  </session-factory>
</hibernate-configuration>

Hehehe, é cara, na verdade eu só fui configurando um monte de coisa pra ver se párava de dar os erros, acabou que dando outros e no final aquele enorme que postei.

Bom só para você ver.
Minha classe AmigoDAO:

[code]import net.sf.hibernate.*;
import net.sf.hibernate.cfg.Configuration;

public class AmigoDAO
{
//Propriedades
private SessionFactory factory;

//Construtor
public AmigoDAO() 
	throws Exception
{
	factory = new Configuration().configure().addClass(Amigo.class).buildSessionFactory();
}
	
//Métodos
public void insert(final Amigo _amigo) 
	throws HibernateException
{
	Session s = this.factory.openSession();
	s.save(_amigo);
	s.flush();
	s.close();
}

public void delete(final Amigo _amigo) 
	throws HibernateException
{
	Session s = this.factory.openSession();
	s.delete(_amigo);
	s.flush();
	s.close();
}

public Amigo retrieve(final String _nome) 
	throws HibernateException
{
	Session s = this.factory.openSession();
	Amigo a = (Amigo) s.load(Amigo.class, _nome);
	s.flush();
	s.close();
	return a;
}

@SuppressWarnings("unchecked")
public java.util.List getList(final String condicao) 
	throws HibernateException
{
	Session s = this.factory.openSession();
	java.util.List amigos = s.find(condicao);
	s.flush();
	s.close();
	return amigos;
}

}[/code]

Minha xml, hibernate.cfg.xml:

[code]<?xml version="1.0" encoding="UTF-8"?>

org.hibernate.dialect.MySQLDialect org.gjt.mm.mysql.Driver jdbc:mysql://127.0.0.1:3306/hibernate root root
<property name="hibernate.connection.autocommit">true</property>  

<mapping resource="Amigo.hbm.xml" />   
[/code]

E minha Amigo.hbm.xml:

[code]<?xml version="1.0" encoding="UTF-8"?>

[/code]

Bom, blz, já substitui o hibernate.cfg.xml que vc me passou.
Ele até executa e aparentemente não há nada e errado, parece que nao lança nenhuma Exception e tal, mas na console aparece isso:

[color=red]02/06/2010 20:32:11 net.sf.hibernate.cfg.Environment
INFO: Hibernate 2.1.8
02/06/2010 20:32:11 net.sf.hibernate.cfg.Environment
INFO: hibernate.properties not found
02/06/2010 20:32:11 net.sf.hibernate.cfg.Environment
INFO: using CGLIB reflection optimizer
02/06/2010 20:32:11 net.sf.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
02/06/2010 20:32:11 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
02/06/2010 20:32:11 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Amigo.hbm.xml
02/06/2010 20:32:12 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: Amigo.hbm.xml
02/06/2010 20:32:12 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
02/06/2010 20:32:12 net.sf.hibernate.cfg.Mappings addClass
WARNING: duplicate class mapping: Amigo
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
16 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
WARNING: No dialect set - using GenericDialect: Could not instantiate dialect class
02/06/2010 20:32:12 net.sf.hibernate.dialect.Dialect
INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
02/06/2010 20:32:12 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
02/06/2010 20:32:12 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
02/06/2010 20:32:12 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://127.0.0.1:3306/hibernate
02/06/2010 20:32:12 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=root, autocommit=true}
02/06/2010 20:32:12 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): true
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
02/06/2010 20:32:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
02/06/2010 20:32:12 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
02/06/2010 20:32:12 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/usuario/Workspace/AmigoNew/lib/ehcache-1.5.0.jar!/ehcache-failsafe.xml
02/06/2010 20:32:12 net.sf.hibernate.impl.SessionFactoryImpl
INFO: building session factory
02/06/2010 20:32:12 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured[/color]

Depois nao acontece mais nada, quando vou olhar no banco, ele nao insertou nada.

É porque vc mapeou sua classe duas vezes

factory = new Configuration().configure().addClass(Amigo.class).buildSessionFactory();   

e no hibernate xml

tira esse add class do seu código, deixa só no xml, se eu não me engano, o addClass funciona apenas qdo vc usa anotações para mapear a classe

Então cara, eu cheguei a tira-lo, pois percebi que estava mapeando duas vezes a mesma classe.
Só que o mesmo erro continua:

[color=red]04/06/2010 21:31:34 net.sf.hibernate.cfg.Environment
INFO: Hibernate 2.1.8
04/06/2010 21:31:34 net.sf.hibernate.cfg.Environment
INFO: hibernate.properties not found
04/06/2010 21:31:34 net.sf.hibernate.cfg.Environment
INFO: using CGLIB reflection optimizer
04/06/2010 21:31:34 net.sf.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
04/06/2010 21:31:34 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
04/06/2010 21:31:34 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
04/06/2010 21:31:34 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Amigo.hbm.xml
04/06/2010 21:31:35 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Amigo -> amigo
04/06/2010 21:31:35 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
04/06/2010 21:31:35 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
04/06/2010 21:31:35 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
04/06/2010 21:31:35 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
0 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
WARNING: No dialect set - using GenericDialect: Could not instantiate dialect class
04/06/2010 21:31:35 net.sf.hibernate.dialect.Dialect
INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
04/06/2010 21:31:35 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
04/06/2010 21:31:35 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
04/06/2010 21:31:35 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://127.0.0.1:3306/hibernate
04/06/2010 21:31:35 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=root, autocommit=true}
04/06/2010 21:31:35 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): true
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
04/06/2010 21:31:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
04/06/2010 21:31:35 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
04/06/2010 21:31:35 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/usuario/Workspace/AmigoNew/lib/ehcache-1.5.0.jar!/ehcache-failsafe.xml
04/06/2010 21:31:36 net.sf.hibernate.impl.SessionFactoryImpl
INFO: building session factory
04/06/2010 21:31:36 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured[/color]

Cara, será que não tem a ver com as linhas:

[color=red]04/06/2010 21:31:35 net.sf.ehcache.config.ConfigurationFactory parseConfiguration
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/usuario/Workspace/AmigoNew/lib/ehcache-1.5.0.jar!/ehcache-failsafe.xml[/color]

Parece que ele não tá conseguindo configurar alguma coisa … estou pesquisando que nem loco sobre isso na net, mas ate agora nada.
Eita, tá dureza de fazer esse Hibernate funcinar, rsrsrs, ou será que eu que sou tonto, pô ja fiz, sem zueira, uns 5 tutoriais de “Meu Primeiro Programa Usando Hibernate”, e todos eles chegaram nesse erro aí.

Tem que configurar alguma coisa na máquina? Sei lah, no BD ?.. li sobre muita gente falando de configurar o JBoss ou Tomcat, mas pra programa JSE (que é o meu caso) não precisa né? … :? … já estou atirando pra todos os lados. rs, mas tá foda.

Esse não é erro

é só um warning

é pq vc tem o jar do ehcache no classpath e não tem configuração para ele

é só colocar a configuração no arquivo do hibernate