Hello!
I'm starting with this great tool and so I been trying to make it work but...
It keeps telling me:
Configured SessionFactory: nullI have this config file:
Code:
<?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>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://myserver:1433</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<!-- <property name="hibernate.format_sql">true</property>-->
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<mapping resource="mapeos/Contacto.hbm.xml"/>
</session-factory>
</hibernate-configuration>
And just this mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC '-//Hibernate/Hibernate Mapping DTD 3.0//EN' 'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>
<hibernate-mapping package="pruebahibernate">
<class name="Contacto" table="CONTACTOS">
<id name="id" column="ID">
<generator class="native" />
</id>
<property name="nombre" type="string" column="NOMBRE" />
<property name="email" />
<property name="telefono" />
</class>
</hibernate-mapping>
The class I want to persist is this:
Code:
package pruebahibernate;
public class Contacto {
private long id;
private String nombre;
private String email;
private String telefono;
public Contacto() {
}
public Contacto(String nombre, String email, String telefono) {
this.nombre = nombre;
this.email = email;
this.telefono = telefono;
}
//<editor-fold defaultstate="collapsed" desc="Getters & Setters">
public long getId() {
return id;
}
private void setId(long id) {
this.id = id;
}
public String getNombre() {
return this.nombre;
}
public String getEmail() {
return this.email;
}
public String getTelefono() {
return this.telefono;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public void setEmail(String email) {
this.email = email;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
//</editor-fold>
}
And the class that calls Hibernate is this:
Code:
package pruebahibernate;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static{
try{
sessionFactory = new Configuration().configure().buildSessionFactory();
}catch(HibernateException he){
System.err.println("Error: " + he);
throw new ExceptionInInitializerError(he);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
Like UB40 says:
Where did I go wrong? Why is SessionFactory null?Thank you in advance.