Sorry for my newie question but I haven't seen any example for that.
My PersistentEnum class:
Code:
package hospital.admin;
import net.sf.hibernate.PersistentEnum;
/**
* @author raul
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TipoUsuario implements PersistentEnum {
private int code;
private String name;
public static final TipoUsuario ADMINISTRADOR =
new TipoUsuario("Administrador");
public static final TipoUsuario ADMINISTRACION =
new TipoUsuario("Administracion");
public static final TipoUsuario FARMACEUTICO =
new TipoUsuario("Farmaceutico");
public static final TipoUsuario MEDICO = new TipoUsuario("Medico");
public static final TipoUsuario DIETISTA = new TipoUsuario("Dietista");
private static int count = 0;
private TipoUsuario(String name) {
this.name = name;
this.code = count++;
}
private TipoUsuario() {
name = null;
code = 0;
}
public static TipoUsuario fromInt(int code) {
switch (code) {
case 0 :
return ADMINISTRADOR;
case 1 :
return ADMINISTRACION;
case 2 :
return FARMACEUTICO;
case 3 :
return MEDICO;
case 4 :
return DIETISTA;
default :
throw new RuntimeException("Unknown TipoUsuario code");
}
}
/* (non-Javadoc)
* @see net.sf.hibernate.PersistentEnum#toInt()
*/
public int toInt() {
// TODO Auto-generated method stub
return code;
}
public String toString() {
return name;
}
}
the xml schema:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="hospital.admin.TipoUsuario" table="tipousuario">
<id name="code" type="long" unsaved-value="null">
<column name="TipoUsuario" not-null="true"/>
<generator class="uuid.string"/>
</id>
<property name="name" column="name" type="string"/>
</class>
</hibernate-mapping>
the exception throwed:
Code:
net.sf.hibernate.PropertyNotFoundException: Object class hospital.admin.TipoUsuario must declare a default (no-argument) constructor
at net.sf.hibernate.util.ReflectHelper.getDefaultConstructor(ReflectHelper.java:122)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:558)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:715)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:41)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:750)
at hospital.SessionManager.updateParams(SessionManager.java:116)
at hospital.SessionManager.<init>(SessionManager.java:77)
at hospital.ApplicationHospital.<init>(ApplicationHospital.java:46)
at hospital.ApplicationHospital.getInstance(ApplicationHospital.java:52)
at hospital.ApplicationHospital.main(ApplicationHospital.java:67)
No se ha podido obtener acceso a la base de datos
Exception in thread "main" java.lang.NullPointerException
at hospital.ApplicationHospital.main(ApplicationHospital.java:69)
In the example on manual for PersistentEnum class Color I haven't seen any default constructor, so I think Im doing something wrong.
If I create a default constructor Hibernates throws me other exception telling me I must declare the getter and setter methods por the properties. And I haven't seen any getter/setter method in Color example class.
Could someone tell me how to correct this problem??
thanks in advance!