Hello, this is my firs time that I use Hibernate.
At first I apologise by my English because I'm spanish and I don't write it very well.
I have spend some time reading forum posts but I can't resolve my problem
Hibernate 3
Hibernate Tools 3
Eclipse 3.1.M4
HSQL 1.7.3.3
I have created a database called "catdb" with one table called "CAT" with two columns "id" and "nom".
I have created a java project in Eclipse.
I have set all necesarie .jar correctly.
I have created "hibernate.cfg.xml" with hibernate tool wizard.
I have created the console with hibernate tool wizard.
I have use hibernate artifact generation wizard to generate all necessary files.
I have created "principal.java" class that instantiate "Cat.java", set its atributes and save the instance in "catdb" database.
All correct and no problem here, but... When I click on the play button I get this message:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:461)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:483)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:50)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1485)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1029)
at scr.principal.main(principal.java:31)
All files, except "principal.java" are been generated automactly by Hibernate Tool Wizard. My code files are:
hibernate.cfg.xmlCode:
<?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>
<property name="hibernate.connection.url">jdbc:hsqldb:catdb</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Cat.hbm.xmlCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class
name="Cat"
table="CAT"
>
<id
name="Id"
type="java.lang.String"
>
<column name="ID" length="32" not-null="true" unique="true" sql-type="VARCHAR" />
<generator class="assigned" />
</id>
<property
name="Nom"
type="java.lang.String"
>
<column name="NOM" length="32" not-null="true" sql-type="VARCHAR" />
</property>
</class>
</hibernate-mapping>
Cat.javaCode:
package scr;
/**
* Cat generated by hbm2java
*/
public class Cat implements java.io.Serializable {
// Fields
private java.lang.String Id;
private java.lang.String Nom;
// Constructors
/** default constructor */
public Cat() {
}
/** constructor with id */
public Cat(java.lang.String Id) {
this.Id = Id;
}
// Property accessors
/**
*/
public java.lang.String getId () {
return this.Id;
}
public void setId (java.lang.String Id) {
this.Id = Id;
}
/**
*/
public java.lang.String getNom () {
return this.Nom;
}
public void setNom (java.lang.String Nom) {
this.Nom = Nom;
}
}
principal.javaCode:
/*
* Creado el 01-mar-2005
*
* TODO Para cambiar la plantilla de este archivo generado, vaya a
* Ventana - Preferencias - Java - Estilo de código - Plantillas de código
*/
package scr;
//import Cat;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
* @author Javier
*
* TODO Para cambiar la plantilla de este comentario generado, vaya a
* Ventana - Preferencias - Java - Estilo de código - Plantillas de código
*/
public class principal {
public static void main(String[] args) throws Exception {
Cat gat = new Cat();
gat.setId("id1");
gat.setNom("caty");
Configuration cfg = new Configuration().addClass(Cat.class);
SessionFactory sf = cfg.buildSessionFactory();
Session sess = sf.openSession();
Transaction t = sess.beginTransaction();
sess.save(gat);
t.commit();
sess.close();
}
}
What can I do?
Thank you in advance