-->
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.  [ 1 post ] 
Author Message
 Post subject: Puzzled with a joined inheritance problem
PostPosted: Thu Sep 10, 2009 8:07 pm 
Newbie

Joined: Sun Aug 23, 2009 8:09 am
Posts: 9
Hello. I have got 4 classes. One superclass and three subclasses. I use a JOINED strategy.

The problem comes with one of the subclasses. If I don't use it or there is no data on the table which represents, all goes OK, but if I retrieve all the instances of the abstract superclass, an error appears as follows:

Cannot instantiate class or interface: es.udc.madtyn.model.puesto.Puesto

Here it goes the code. I can't understand why it works with two subclasses (Monitor and Administrativo), but it doesn't work with the analogous third subclass Mantenimiento.

Any help will be appreciated. Thanks.



Code:
                                            /*SUPERCLASS*/
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name="idPuesto")
public abstract class Puesto implements Serializable {
   
   private Long idPuesto;
   private double salBase;
   private long version;
   
   public Puesto() {}
   
   public Puesto(double salBase) {
      this.salBase = salBase;
   }

   @SequenceGenerator(name="IdPuestoGenerator",
         sequenceName="PuestoSeq")
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO,
               generator="IdPuestoGenerator")
   public Long getIdPuesto() {
      return idPuesto;
   }

   public void setIdPuesto(Long idPuesto) {
      this.idPuesto = idPuesto;
   }

   public double getSalBase() {
      return salBase;
   }

   public void setSalBase(double salBase) {
      this.salBase = salBase;
   }
   @Version
   public long getVersion() {
      return version;
   }

   public void setVersion(long version) {
      this.version = version;
   }

   /* HASHCODE AND EQUALS METHODS*/

   @Transient
   public String getLabel() {
      return "";
   }
}

                      /* THE TWO CORRECT SUBCLASSES ARE DOWN HERE, FOLLOWED BY THE WRONG ONE        */

@Entity
@PrimaryKeyJoinColumn(name = "idPuesto")
public class Administrativo extends Puesto {

   private String cargo;
   private double plus;

   public Administrativo() {
      super();
   }

   public Administrativo(double salBase, String cargo, double plus) {
      super(salBase);
      this.cargo = cargo;
      this.plus = plus;
   }

   public String getCargo() {
      return cargo;
   }

   public void setCargo(String cargo) {
      this.cargo = cargo;
   }

   public double getPlus() {
      return plus;
   }

   public void setPlus(double plus) {
      this.plus = plus;
   }

   /* HASHCODE AND EQUALS METHODS*/

   @Transient
   @Override
   public String getLabel() {
      return "Administrativo: " + cargo;
   }
}

@Entity
@PrimaryKeyJoinColumn(name = "idPuesto")
public class Monitor extends Puesto {

   private String especialidad;
   private double plus;

   public Monitor() {
      super();
   }

   public Monitor(double salBase, String especialidad, double plus) {
      super(salBase);
      this.especialidad = especialidad;
      this.plus = plus;
   }

   public String getEspecialidad() {
      return especialidad;
   }

   public void setEspecialidad(String especialidad) {
      this.especialidad = especialidad;
   }

   public double getPlus() {
      return plus;
   }

   public void setPlus(double plus) {
      this.plus = plus;
   }

   /* HASHCODE AND EQUALS METHODS*/

   @Transient
   @Override
   public String getLabel() {
      return "Monitor: " + especialidad;
   }
}

                          /* THE NO WORKING SUBCLASS IS DOWN HERE*/

@Entity
@PrimaryKeyJoinColumn(name = "idPuesto")
public class Mantenimiento extends Puesto {
   
   private String denom;
   private double plus;

   public Mantenimiento() {
      super();
   }

   public Mantenimiento(double salBase, String denom, double plus) {
      super(salBase);
      this.denom = denom;
      this.plus = plus;
   }

   @Column(name="denom")
   public String getDenom() {
      return denom;
   }

   public void setDenom(String denom) {
      this.denom = denom;
   }

   @Column(name="plus")
   public double getPlus() {
      return plus;
   }

   public void setPlus(double plus) {
      this.plus = plus;
   }

   /* HASHCODE AND EQUALS METHODS*/

   @Transient
   @Override
   public String getLabel() {
      return "Mantenimiento: " + denom;
   }
}


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

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.