Hello,
I'm newbe so I thik that I followed correctly the configuration manual.
This is the file hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bbw</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.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.HSQLDialect</property> -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- Transaction properties -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping resource="Usuario.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The file that represents the Java class to map is:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 28, 2012 4:05:29 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="registrar.model.Usuario" table="usuario" catalog="bbw">
<id name="usuario" type="string">
<column name="usuario" />
<generator class="assigned" />
</id>
<property name="nombre" type="string">
<column name="nombre" length="15" />
</property>
<property name="apellido" type="string">
<column name="apellido" length="10" />
</property>
<property name="NIFCIF" type="string">
<column name="NIFCIF" length="9" />
</property>
<property name="email" type="string">
<column name="email" length="30" />
</property>
<property name="telefono" type="string">
<column name="telefono" length="9" />
</property>
<property name="empresa" type="string">
<column name="empresa" length="15" />
</property>
<property name="departamento" type="string">
<column name="departamento" length="10" />
</property>
<property name="contrasena" type="string">
<column name="contrasena" length="15" />
</property>
</class>
</hibernate-mapping>
I manage the hibernate session with this java classe:
Code:
package utils;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
Configuration configuration = new Configuration();
configuration = configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
The problem is that the database did not insert any, so I can see in the console that says:
Code:
hibernate: insert into bbw.usuario (nombre, apellido, NIFCIF, email, telefono, empresa, departamento, contrasena, usuario) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Can anyone givme a hand?
Thanks!