Vejam as saidas do console, para entenderem meu dilema:
2006-09-01 14:01:11,421 INFO cfg.annotations.Version -> Hibernate Annotations 3.2.0.CR1
2006-09-01 14:01:11,453 INFO hibernate.cfg.Environment -> Hibernate 3.2 cr2
2006-09-01 14:01:11,453 INFO hibernate.cfg.Environment -> hibernate.properties not found
2006-09-01 14:01:11,468 INFO hibernate.cfg.Environment -> Bytecode provider name : cglib
2006-09-01 14:01:11,468 INFO hibernate.cfg.Environment -> using JDK 1.4 java.sql.Timestamp handling
2006-09-01 14:01:11,640 INFO hibernate.cfg.Configuration -> configuring from resource: res/cfg/scidata.con.xml
2006-09-01 14:01:11,640 INFO hibernate.cfg.Configuration -> Configuration resource: res/cfg/scidata.con.xml
2006-09-01 14:01:11,781 INFO hibernate.cfg.Configuration -> Configured SessionFactory: null
2006-09-01 14:01:11,859 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.Bairro
2006-09-01 14:01:11,906 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.Bairro on table Bairro
2006-09-01 14:01:12,000 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.CaixaPostalComunitaria
2006-09-01 14:01:12,015 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.CaixaPostalComunitaria on table CaixaPostalComunitaria
2006-09-01 14:01:12,015 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.Cidade
2006-09-01 14:01:12,015 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.Cidade on table Cidade
2006-09-01 14:01:12,015 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.Estado
2006-09-01 14:01:12,015 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.Estado on table Estado
2006-09-01 14:01:12,031 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.GrandesUsuarios
2006-09-01 14:01:12,031 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.GrandesUsuarios on table GrandesUsuarios
2006-09-01 14:01:12,031 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.Logradouro
2006-09-01 14:01:12,031 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.Logradouro on table Logradouro
2006-09-01 14:01:12,046 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.geo.UnidadeOperacional
2006-09-01 14:01:12,046 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.geo.UnidadeOperacional on table UnidadeOperacional
2006-09-01 14:01:12,062 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.finance.Banco
2006-09-01 14:01:12,062 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.finance.Banco on table Banco
2006-09-01 14:01:12,062 INFO hibernate.cfg.AnnotationBinder -> Binding entity from annotated class: br.com.drisoft.jscidata.beans.security.Usuario
2006-09-01 14:01:12,062 INFO cfg.annotations.EntityBinder -> Bind entity br.com.drisoft.jscidata.beans.security.Usuario on table Usuario
2006-09-01 14:01:12,312 INFO hibernate.connection.DriverManagerConnectionProvider -> Using Hibernate built-in connection pool (not for production use!)
2006-09-01 14:01:12,312 INFO hibernate.connection.DriverManagerConnectionProvider -> Hibernate connection pool size: 1
2006-09-01 14:01:12,312 INFO hibernate.connection.DriverManagerConnectionProvider -> autocommit mode: false
2006-09-01 14:01:12,312 INFO hibernate.connection.DriverManagerConnectionProvider -> using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://servidor/bancoteste
2006-09-01 14:01:12,312 INFO hibernate.connection.DriverManagerConnectionProvider -> connection properties: {user=root, password=****}
2006-09-01 14:01:18,984 WARN hibernate.cfg.SettingsFactory -> Could not obtain connection metadata
java.sql.SQLException: Access denied for user: 'root@servidor' (Using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1235)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2644)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
at br.com.drisoft.jscidata.persistence.hibernate.HibernateUtility.getFactory(HibernateUtility.java:116)
at br.com.drisoft.jscidata.persistence.hibernate.HibernateUtility.getSession(HibernateUtility.java:28)
at br.com.drisoft.jscidata.App$1.run(App.java:19)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
2006-09-01 14:01:19,109 INFO hibernate.dialect.Dialect -> Using dialect: org.hibernate.dialect.MySQLDialect
2006-09-01 14:01:19,109 INFO hibernate.transaction.TransactionFactoryFactory -> Using default transaction strategy (direct JDBC transactions)
2006-09-01 14:01:19,125 INFO hibernate.transaction.TransactionManagerLookupFactory -> No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Automatic flush during beforeCompletion(): disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Automatic session close at end of transaction: disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Scrollable result sets: disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> JDBC3 getGeneratedKeys(): disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Connection release mode: auto
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Maximum outer join fetch depth: 1
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Default batch fetch size: 1
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Generate SQL with comments: disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Order SQL updates by primary key: disabled
2006-09-01 14:01:19,125 INFO hibernate.cfg.SettingsFactory -> Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-09-01 14:01:19,156 INFO hql.ast.ASTQueryTranslatorFactory -> Using ASTQueryTranslatorFactory
2006-09-01 14:01:19,156 INFO hibernate.cfg.SettingsFactory -> Query language substitutions: {}
2006-09-01 14:01:19,156 INFO hibernate.cfg.SettingsFactory -> Second-level cache: enabled
2006-09-01 14:01:19,156 INFO hibernate.cfg.SettingsFactory -> Query cache: disabled
2006-09-01 14:01:19,156 INFO hibernate.cfg.SettingsFactory -> Cache provider: org.hibernate.cache.EhCacheProvider
2006-09-01 14:01:19,171 INFO hibernate.cfg.SettingsFactory -> Optimize cache for minimal puts: disabled
2006-09-01 14:01:19,171 INFO hibernate.cfg.SettingsFactory -> Structured second-level cache entries: disabled
2006-09-01 14:01:19,187 INFO hibernate.cfg.SettingsFactory -> Echoing all SQL to stdout
2006-09-01 14:01:19,187 INFO hibernate.cfg.SettingsFactory -> Statistics: enabled
2006-09-01 14:01:19,187 INFO hibernate.cfg.SettingsFactory -> Deleted entity synthetic identifier rollback: disabled
2006-09-01 14:01:19,187 INFO hibernate.cfg.SettingsFactory -> Default entity-mode: pojo
2006-09-01 14:01:19,296 INFO hibernate.impl.SessionFactoryImpl -> building session factory
2006-09-01 14:01:19,312 WARN ehcache.config.ConfigurationFactory -> No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/Adriano/workspace/jscidata/lib/ehcache-1.2.jar!/ehcache-failsafe.xml
2006-09-01 14:01:20,125 INFO hibernate.impl.SessionFactoryObjectFactory -> Not binding factory to JNDI, no JNDI name configured
Aqui, simulei uma falha de conexão com o Banco, portanto surge uma exceção no Driver JDBC do MySQL, conforme segue: com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946), com a mensagem: java.sql.SQLException: Access denied for user: ‘root@servidor’ (Using password: YES)
Pois é exatamente essa exeção que desejo capturar.
Mesmo usando Try/Catch, essa exeção não é considerada e passa normalmente. O que pode ser? O que devo fazer?