Sres.(as), meu projeto estadando o seguinte erro:
Erro aoiniciar a sessionFactory. Erro: Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException
Exception in thread “main” java.lang.NullPointerException
at br.com.javaparaweb.capitulo3.conexao.ConectaHibernateMySQL.main(ConectaHibernateMySQL.java:16)
O que pode ser? Até o exemplo do livro da o erro.
import org.hibernate.Session;
public class ConectaHibernateMySQL {
public static void main(String[] args) { Session sessao = null; try { sessao = HibernateUtil.getSessionFactory().openSession(); System.out.println("Conectado"); } finally
{ sessao.close();
} }
}
Classe hibernate
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory(){
try{ Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder registradorServico = new StandardServiceRegistryBuilder(); registradorServico.applySettings(cfg.getProperties()); StandardServiceRegistry servico= registradorServico.build(); return cfg.buildSessionFactory(servico); }catch (Throwable e){ System.out.println("Erro aoiniciar a sessionFactory. Erro: " + e.getMessage()); throw new ExceptionInInitializerError(e); }
}
Classe hibernate.cfg.xml
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/agenda</property> <property name="connection.username">root</property> <property name="connection.password">123456</property> <property name="current_session_context_class">thread</property>
<property name="c3po.min_size">5</property> <property name="c3po.max.sixe">20</property> <property name="c3po.timeout">300</property> <property name="c3po.max_statements">50</property> <property name="c3po.idle_test_period">3000</property>
<property name="show_sql">true</property> <property name="format_sql">true</property> <property name="generete_statistics">true</property> <property name="use_sql_comments">true</property>