Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Inheritance. Exception "Missing class for indicator field value"

Hi,

I'm new to EclipseLink and I'm trying to implement inheritance. I'm using
SINGLE-TABLE strategy. I have one abstract class "Persona" and three classes
that extend from it: "Empleado", "Supervisor" and "Operario". These are
types of employees. These 3 classes extend from "Persona" and don't have any
difference so far in attributes or methods.

The problem is an exception that raises whenever the application tries to
query all the elements from the table. To do this, I use a named query
defined in abstract class "Persona". The odd thing is this exception only
raises when there is a type "Supervisor" or a type "Operario" persisted in
the table. There is no problem if all the rows of the table have its type
column (TIPO) set to "EMP". This type corresponds to Entity "Empleado" in
the Object model.

I'm just pretty confused. If someone could help me it would be very
appreciated.
Thank you!

This is the file persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";>
  <persistence-unit name="BioId_ClientPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>ar.com.ambest.BioID.modelo.Persona</class>
    <class>ar.com.ambest.BioID.modelo.Operario</class>
    <class>ar.com.ambest.BioID.modelo.Supervisor</class>
    <class>ar.com.ambest.BioID.modelo.Empleado</class>
    <properties>
      <property name="javax.persistence.jdbc.url"
value="jdbc:derby://localhost:1527/bioid"/>
      <property name="javax.persistence.jdbc.password" value="bio"/>
      <property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="bio"/>
    </properties>
  </persistence-unit>
</persistence>

The entity classes are the following:

@Entity
@Table(name = "PERSONA")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TIPO",
discriminatorType=DiscriminatorType.STRING, length=5)
@NamedQuery(name = "Persona.buscarTodos", query = "SELECT p FROM Persona p")
public abstract class Persona implements Serializable {
    protected static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    protected Integer id;

    @Column(name = "ID_SUP")
    protected Integer idSup;

    @Column(name = "NOMBRE_SUP")
    protected String nombreSup;

    @Column(name = "DNI")
    protected String dni;
    
    ...
   
    @Column(name = "TIPO")
    protected String tipo;

    public Persona() {
    }

    public Persona(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

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

    public Integer getIdSup() {
        return idSup;
    }

    public void setIdSup(Integer idSup) {
        this.idSup = idSup;
    }

    public String getNombreSup() {
        return nombreSup;
    }

    public void setNombreSup(String nombreSup) {
        this.nombreSup = nombreSup;
    }

    public String getDni() {
        return dni;
    }

    public void setDni(String dni) {
        this.dni = dni;
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields
are not set
        if (!(object instanceof Persona)) {
            return false;
        }
        Persona other = (Persona) object;
        if ((this.id == null && other.id != null) || (this.id != null &&
!this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ar.com.ambest.BioID.modelo.Persona[dni=" + dni + "]";
    }
}

@Entity
@DiscriminatorValue("OPR")
@NamedQuery(name = "Operario.buscarTodos", query = "SELECT o FROM Operario
o")
public class Operario extends Persona implements Serializable {

    @Override
    public String toString() {
        return "ar.com.ambest.BioID.modelo.Operario[dni=" + dni + "]";
    }
}

@Entity
@DiscriminatorValue("SUP")
@NamedQuery(name = "Supervisor.buscarTodos", query = "SELECT s FROM
Supervisor s")
public class Supervisor extends Persona implements Serializable {

    @Override
    public String toString() {
        return "ar.com.ambest.BioID.modelo.Supervisor[dni=" + dni + "]";
    }
}

@Entity
@DiscriminatorValue("EMP")
@NamedQuery(name = "Empleado.buscarTodos", query = "SELECT e FROM Empleado
e")
public class Empleado extends Persona implements Serializable {

    @Override
    public String toString() {
        return "ar.com.ambest.BioID.modelo.Supervisor[dni=" + dni + "]";
    }
}
-- 
View this message in context: http://old.nabble.com/Inheritance.-Exception-%22Missing-class-for-indicator-field-value%22-tp30180957p30180957.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top