Estou usando Hibernate para gerar as tabelas, e tenho sucesso, porém quando vou salvar ocorrre esse erro. Segue meu codigo:
Hibernate.cfg
<session-factory>
<!--Configurações de conexão com banco de dados hibernate -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">"jdbc:postgresql://localhost:5432/db_loja?autoReconnect=true"</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="connection.username">postgres</property>
<property name="connection.password">admin</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">20</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</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.internal.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>
<mapping class="domain.Fabricante" />
<mapping class="domain.Funcionario" />
<mapping class="domain.Produto" />
<mapping class="domain.Venda" />
<mapping class="domain.ItensVenda" />
</session-factory>
HibernateUtil
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Criando a fabrica de sessao no Hibernate.cfg
Configuration configuration = new Configuration();
configuration.configure();//busca configuraçoes do hibernate.cfg
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory =configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
//-------------------------------------------------------------
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println("A criação da sessao falhou no hibernateUtil" + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Dao
public class FabricanteDao {
public void salvar(Fabricante fabricante) {
Session sessao = HibernateUtil.getSessionFactory().openSession();
Transaction transacao = null;
try {
transacao = sessao.beginTransaction();
sessao.save(fabricante);
transacao.commit();
} catch (RuntimeException e) {
if (transacao != null) {
transacao.rollback();
}
} finally {
sessao.close();
}
}
}
DaoTeste
@Test
//@Ignore
public void teste_salvar() {
Fabricante f4 = new Fabricante();
f4.setDescricao("Ceramica Nova Garça");
Fabricante f3 = new Fabricante();
f3.setDescricao("Telhas Mundo Novo");
FabricanteDao dao = new FabricanteDao();
dao.salvar(f3);
dao.salvar(f4);
}