Boa noite pessoa do GUJ!
Sumi por um tempo aqui do fórum. Passei bom tempo estudando outros assuntos do Java. Agora, comprei um livro de Hibernate (“Java persistence com hibernate”) e quis começar do novo meus estudos. Sem mais apostilas incompletas!
A minhas dúvida está em manipulação de dados em uma tabela. Algo estupidamente simples (para mim, não tá sendo), inserir uma pessoa na tabela pessoa no banco de dados. A tabela só tem dois campos, id e nome da pessoa. Acontece que quando inicio o meu método main, aparece as informações do log e tal, e, depois, algo de errado acontece. O mapeamento de minha tabela foi feita usando XML e não anotações. Não estou sabendo como consertar isso no momento. Se alguém puder me dar uma luz:
18/12/2010 20:54:51 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.1.3
18/12/2010 20:54:51 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
18/12/2010 20:54:51 org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
18/12/2010 20:54:51 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
18/12/2010 20:54:51 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: xmls/configurador/hibernate.cfg.xml
18/12/2010 20:54:51 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: xmls/configurador/hibernate.cfg.xml
18/12/2010 20:54:52 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: xmls/pojos/Pessoa.hbm.xml
18/12/2010 20:54:52 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pojos.Pessoa -> pessoa
18/12/2010 20:54:52 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
18/12/2010 20:54:52 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://127.0.0.1:3307/estudo_hibernate
18/12/2010 20:54:52 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=hibernate, password=****}
18/12/2010 20:54:52 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: false
18/12/2010 20:54:52 com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
18/12/2010 20:54:52 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.0 [built 11-July-2005 00:43:29 -0400; debug? true; trace: 10]
18/12/2010 20:54:52 com.mchange.v2.c3p0.PoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1125127 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@72ffb [ 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 -> 72ffb, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxIdleTime -> 300, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@3901c6 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 3901c6, jdbcUrl -> jdbc:hsqldb:hsql://127.0.0.1:3307/estudo_hibernate, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> 1125127, numHelperThreads -> 3 ]
18/12/2010 20:55:51 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
AVISO: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15212bc -- 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).
18/12/2010 20:55:51 org.hibernate.cfg.SettingsFactory buildSettings
AVISO: 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:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at utilidades.HibernateUtil.<clinit>(HibernateUtil.java:14)
at testes.PessoaTeste.main(PessoaTeste.java:12)
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.awaitAcquire(BasicResourcePool.java:970)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
... 7 more
18/12/2010 20:55:51 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.HSQLDialect
18/12/2010 20:55:52 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
18/12/2010 20:55:52 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
18/12/2010 20:55:52 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
18/12/2010 20:55:52 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:327)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:219)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at utilidades.HibernateUtil.<clinit>(HibernateUtil.java:14)
at testes.PessoaTeste.main(PessoaTeste.java:12)
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.CacheException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 11 more
Exception in thread "main" java.lang.NullPointerException
at testes.PessoaTeste.main(PessoaTeste.java:12)
Gggrrrrr!!! :x
Esse maldito está me matando “Could not obtain connection metadata”. Não sei o que significa.
Olha só o meu arquivo hibernate.cfg.xml:
[code]<?xml version="1.0"?>
<property name = "hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name = "hibernate.connection.url">jdbc:hsqldb:hsql://127.0.0.1:3307/estudo_hibernate</property>
<property name = "hibernate.connection.username">hibernate</property>
<property name = "hibernate.connection.password">hibernate</property>
<property name = "hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Utiliza c3p0 para gerenciar pool de conexões com banco -->
<property name = "hibernate.c3p0.min_size">5</property>
<property name = "hibernate.c3p0.max_size">20</property>
<property name = "hibernate.c3p0.timeout">300</property>
<property name = "hibernate.c3p0.max_statements">50</property>
<property name = "hibernate.c3p0.idle_test_period">3000</property>
<property name = "show_sql">true</property>
<property name = "format_sql">true</property>
<mapping resource = "xmls/pojos/Pessoa.hbm.xml"/>
</session-factory>
[/code]
No tópico tá aparecendo que a URL está assim “estudo hibernate”. Mas na verdade, está sublinhado assim: “estudo_hibernate”.
E meus jars do Hibernate são esses:
astlr-2.7.5H3.jar
asm-attrs.jar
asm.jar
c3p0-0.9.0.jar
cglib-2.1.jar
commons-collections-3.2.jar
commons-logging.jar
dom4j-1.6.jar
hibernate3.jar
hsqldb-1.7.2.2.jar
jta.jar
Até com a ferramenta do próprio Hibernate, a HSQL Database Manager, eu não consigo me conectar ao banco de dados. Quando vou me conectar, aparece um “java.sql.SQLException: socket creation error”. Ai ai… Ficarei grato se alguém pelo menos me der uma dica do que diabos pode ser isso. Eu falei com meu professor pelo msn uma vez, e o infeliz ainda falou: “Calma, daqui pra frente ainda piora!”. :shock:
Abraços GUJ!