olá pessoal, sou novato no hibernate..mas vamos ao que interessa.
quando tento fazer uma inserção no hibernate utilizando uma Jdailog fora do pacote raiz,pois tenho que obdecer a um padrão MVC. e banco Mysql.
Caso eu faça a chamada no pacote raiz ele funfa, mas como citado acima utilizo um ppadrão que deve ser respeita.
há e todo o código foi tirado de exemplos do proprio hibernate.
23/10/2010 13:30:56 view.tipoInstituicao.CadastrarTipoInstituicao jButton1ActionPerformed
SEVERE: null
org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:107)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:142)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at control.TipoInstituicaoDAO.<init>(TipoInstituicaoDAO.java:22)
at view.tipoInstituicao.CadastrarTipoInstituicao.jButton1ActionPerformed(CadastrarTipoInstituicao.java:162)
at view.tipoInstituicao.CadastrarTipoInstituicao.access$100(CadastrarTipoInstituicao.java:23)
at view.tipoInstituicao.CadastrarTipoInstituicao$2.actionPerformed(CadastrarTipoInstituicao.java:103)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6108)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:5873)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4469)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:194)
at java.awt.Dialog$1.run(Dialog.java:1072)
at java.awt.Dialog$3.run(Dialog.java:1126)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1124)
at java.awt.Component.show(Component.java:1464)
at java.awt.Component.setVisible(Component.java:1416)
at java.awt.Window.setVisible(Window.java:842)
at java.awt.Dialog.setVisible(Dialog.java:1011)
at view.tipoInstituicao.CadastrarTipoInstituicao$3.run(CadastrarTipoInstituicao.java:186)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
public class TipoInstituicaoDAO {
private SessionFactory factory;
public TipoInstituicaoDAO() throws Exception{
factory = new Configuration().addClass(TipoInstituicao.class).buildSessionFactory();
}
public void insertTipoInstituicao(TipoInstituicao us) throws Exception {
Session session = factory.openSession();
session.save(us);
session.flush();
session.close();
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
TipoInstituicaoDAO tidao = new TipoInstituicaoDAO();
tidao.insertTipoInstituicao(getCampoTipoInstituicao());
this.dispose();
} catch (Exception ex) {
Logger.getLogger(CadastrarTipoInstituicao.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernete</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</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.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 resource="model/Event.hbm.xml"/>
<mapping resource="model/TipoInstituicao.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="model">
<class name="TipoInstituicao" table="tipoInstituicao">
<id name="codigo" column="codigo">
<generator class="assigned"/>
</id>
<property name="tipo"/>
<property name="nome"/>
</class>
</hibernate-mapping>