-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to make the xml schema for PersistentEnum types?
PostPosted: Fri Apr 02, 2004 2:31 pm 
Newbie

Joined: Fri Apr 02, 2004 2:19 pm
Posts: 1
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!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 3:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
TipoUsuario is a property persister, not a class to map
Code:
<property name="myType" type"....TipoUsuario">

It is done to map an enum into one column.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.