Neste código está ocorrendo este erro:
ocorre quando tento pegar o session do hibernate.
Exception in thread “AWT-EventQueue-0” java.lang.ExceptionInInitializerError
at utils.ConnectDB.<clinit>(ConnectDB.java:36)
at dao.FreteHibernateDAO.consultarTabela(FreteHibernateDAO.java:59)
at gui.JanelaCadastrarFrete.initComponents(JanelaCadastrarFrete.java:62)
at gui.JanelaCadastrarFrete.<init>(JanelaCadastrarFrete.java:31)
at teste.TesteHibernate$1.run(TesteHibernate.java:33)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/query/sql/NativeSQLQueryReturn
at org.hibernate.cfg.annotations.QueryBinder.bindSqlResultsetMapping(QueryBinder.java:295)
at org.hibernate.cfg.AnnotationBinder.bindQueries(AnnotationBinder.java:239)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:404)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:26
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:116
at utils.ConnectDB.<clinit>(ConnectDB.java:34)
… 11 more
O que pode ser?
Como é que vc está criando o seu Session? Como está o seu hibernate.cfg.xml ?
Quando chamo o método em negrito
public List consultarTabela(String tabela)
{
session = ConnectDB.getInstance();
List lista = session.createQuery("from " + tabela ).list();
return lista;
}
classe que faz a conexão
package utils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
//responsável por acessar os metadas acessados por anotações
import org.hibernate.cfg.AnnotationConfiguration;
//responsável por identificar qual a abordagem para o mapeamento das classes
import org.hibernate.cfg.Configuration;
/**
*
-
@author tom
*/
public class ConnectDB
{
private static final SessionFactory sessionFactory;
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
static {
try {
Configuration configuration = new AnnotationConfiguration();
configuration.configure(“hibernate.cfg.xml”);
//
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}
public static Session getInstance()
{
Session session = (Session) threadLocal.get();
session = sessionFactory.openSession();
threadLocal.set(session);
return session;
}
/** Creates a new instance of ConnectDB */
public ConnectDB()
{
}
}
hibernate.cfg.xml
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory name=“exemplo_hibernate”>
<property name=“hibernate.connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=“hibernate.connection.password”>usuario</property>
<property name=“hibernate.connection.url”>jdbc:mysql://localhost/hibernate</property>
<property name=“hibernate.connection.username”>senha</property>
<property name=“hibernate.dialect”>org.hibernate.dialect.MySQLDialect</property>
<mapping class=“dominio.Cliente” />
<mapping class=“dominio.Cidade” />
<mapping class=“dominio.Frete” />
</session-factory>
</hibernate-configuration>
Valeu pela ajuda
Me ajudem com este erro!! Nâo consigo resolver!!!