<!-- Configurações da conexão com o Banco -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/vendaspecas</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">12345</property>
<!-- Config da conexao JDBC Mysql -->
<property name="hibernate.connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- Gerenciamento da sessão mysql -->
<property name="current_session_context_class">thread</property>
<!-- Desabilita o cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Exibe os comando SQL -->
<property name="show_sql">true</property>
<!-- Criação das tabelas -->
<property name="hbm2ddl.auto">update</property>
<mapping class="br.com.VendasPecas.domain.Fornecedor" />
<mapping class="br.com.VendasPecas.domain.Funcionario" />
<mapping class="br.com.VendasPecas.domain.Produto" />
<mapping class="br.com.VendasPecas.domain.Vendas" />
<mapping class="br.com.VendasPecas.domain.Item" />
</session-factory>
HibernateUtil
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Cria uma conexão a partir do hibernate.cfg.xml
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
//return new Configuration().configure().buildSessionFactory(
// new StandardServiceRegistryBuilder().build() );
}
catch (Throwable ex) {
// Mensagem de erro ao conectar
System.err.println("Erro na conexão." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Erro: Erro na conexão.org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect Exception in thread "main" java.lang.ExceptionInInitializerError at br.com.VendasPecas.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:34) at br.com.VendasPecas.util.HibernateUtil.(HibernateUtil.java:10) at br.com.VendasPecas.main.GerarTabela.main(GerarTabela.java:9) Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132) at
`