Error in Eclipse: Enum class not found

0

You see, I have a table called Seguro, with the following characteristics.

    package es.makigas.hibernate.modelo;

import java.io.Serializable;

public class Seguro implements Serializable{
    public enum Sexo{
         Hombre,
         Mujer
    }

private static final long serialVersionUID = 1L;

int id;
Sexo sexo;


public Seguro() {}

public Seguro(Sexo sexo){
    this.sexo = sexo;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public Sexo getSexo() {
    return sexo;
}

public void setSexo(Sexo sexo) {
    this.sexo = sexo;
}
}

And file Seguro.hbm.xml:

    <?xml version="1.0" encoding="UTF-8"?>

<hibernate-mapping>
  <class name="es.makigas.hibernate.modelo.Seguro" >
    <id column="Id" name="id" type="integer">
        <generator class="increment" />
    </id>

    <property name="sexo" >
        <type name="org.hibernate.type.EnumType">
            <param name="enumClass">es.makigas.hibernate.modelo.Sexo</param>
        </type>
    </property>

  </class>
</hibernate-mapping>

However, when I run the program, I run into this error:

Enum class not found: es.makigas.hibernate.modelo.Sexo

What will be wrong?

Edit: I tried this change in Seguro.hbm.xml:

<property name="sexo" >
        <type name="org.hibernate.type.EnumType">
            <param name="enumClass">es.makigas.hibernate.modelo.Seguro.Sexo</param>
            <param name="type">4</param>
        </type>
    </property>

But I run into this:

    
asked by Miguel Alparez 27.02.2018 в 17:19
source

2 answers

1

The name of the class is es.makigas.hibernate.modelo.Seguro.Sexo , since it is an internal class of es.makigas.hibernate.modelo.Seguro .

    
answered by 27.02.2018 в 17:56
0

I have already found a solution. From the outset, I've taken out the listed Sex from the Safe class and passed it to a class Sex:

package es.makigas.hibernate.modelo;

public enum Sexo{
    Hombre,
    Mujer
}

From there, the last thing was to change the configuration in Seguro.hbm.xml:

<property name="sexo" >
        <type name="org.hibernate.type.EnumType">
            <param name="enumClass">es.makigas.hibernate.modelo.Sexo</param>
        </type>
</property>
    
answered by 27.02.2018 в 19:54