Hi,
I'm starting a project with Hibernate and I just cannot work because a blocking error that occurs. First, let me introduce the environment:
Code:
Ubuntu 10.x
Eclipse 3.7 indigo
Hibernate 4
HSQLDB
So, I've got a class like this (sorry for spanish)
Code:
package dominio;
public class Empresa {
private int id;
private String nombre;
private String direccion;
private String telefono;
private String email;
private String poblacion;
public int getId(){
return this.id;
}
public void setId(int id){
this.id=id;
}
public String getNombre(){
return this.nombre;
}
public void setNombre(String value){
this.nombre = value;
}
public String getDireccion(){
return this.direccion;
}
public void setDireccion(String value){
this.direccion = value;
}
public String getTelefono(){
return this.telefono;
}
public void setTelefono(String value){
this.telefono = value;
}
public String getEmail(){
return this.email;
}
public void setEmail(String value){
this.email = value;
}
public String getPoblacion(){
return this.poblacion;
}
public void setPoblacion(String value){
this.poblacion = value;
}
}
That's simply a class that maps a record of a company in a contability system. Here follows its mapping xml file:
Code:
<?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>
<class name="dominio.Empresa" table="EMPRESA">
<id name="id" type="int">
<column name="ID_EMPRESA" />
<generator class="assigned" />
</id>
<property name="nombre" type="java.lang.String">
<column name="NOMBRE" />
</property>
<property name="direccion" type="java.lang.String">
<column name="DIRECCION" />
</property>
<property name="telefono" type="java.lang.String">
<column name="TELEFONO" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="poblacion" type="java.lang.String">
<column name="POBLACION" />
</property>
</class>
</hibernate-mapping>
Now, if I switch to the hibernate view and look at configurations, it seems that everything is allright, as I can browse db structure, open mapping diagram, etc....
But when I try to run a "hello world" program, it suddenly crash. Here my main():
Code:
.....
public static void main(String[] args) {
Session session = UtilityHibernate.getSessionFactory().openSession();
Empresa emp = new Empresa();
emp.setId(5);
emp.setNombre("mercadona");
session.save(emp); <-- HERE IT CRASHES
session.close();
}
....
The error comunicates me:
Quote:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: dominio.Empresa
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1190)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1316)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:670)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:662)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:658)
at arranque.main(arranque.java:18)
Why does it happen? I'm quite stuck in this mess, I can't get over.
Thanks