-->
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: Three level hierarchy mapping on single teble strategy
PostPosted: Wed Jun 05, 2013 4:37 pm 
Newbie

Joined: Tue Apr 12, 2011 3:20 am
Posts: 3
Hi,

I'm trying to map a class hierarchy of three levels using the single table strategy with joined tables for middle classes (level 2 on hierarchy).

These are my class definitions (w/o getters&setters)

First level class:

Code:
@Entity
@Table(name = Operacion.TABLE_NAME)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TIPO", discriminatorType = DiscriminatorType.STRING)
public abstract class Operacion {
   public static final String TABLE_NAME = "TB_OPERACION";
   
   @Id
   @Column(name="ID_OPERACION")
   @SequenceGenerator(name="op_seq", sequenceName="TB_OPERACION_ID_GENERATOR")
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="op_seq")
   private Long idOperacion;
   
   @Column(name="ASUNTO", length=1024)
   private String asunto;
   
   @Column(name="FECHA_INICIO_OPERACION")
   private Timestamp fechaInicioOperacion;
   
   @Column(name="FECHA_FIN_OPERACION")
   private Timestamp fechaFinOperacion;
   
   @Column(name="RESULTADO")
   private int resultado;
   
   @Column(name="USUARIO", length=10)
   private String usuario;
}


Second level class:

Code:
@Entity
@SecondaryTable(name=Peticion.TABLE_NAME, pkJoinColumns = @PrimaryKeyJoinColumn(name="ID_OPERACION"))
public abstract class Peticion extends Operacion {
   public static final String TABLE_NAME = "TB_OP_PETICION";
   
   @Column(table=TABLE_NAME, name="ESTADO")
   private int estado;
}


Third level class:

Code:
@Entity
@SecondaryTable(name = Peticion.TABLE_NAME, pkJoinColumns = @PrimaryKeyJoinColumn(name="ID_OPERACION"))
public class PeticionCambioEstado extends Peticion {

   @Column(table=Peticion.TABLE_NAME, name="CE_COMENTARIO", length=1024)
   private String comentario;
   
   @Column(table=Peticion.TABLE_NAME, name="CE_NUEVO_ESTADO")
   private int nuevoEstado;
   
}


With these mappings when I tried to save a PeticionCambioEstado I get an error cause hibernate does three inserts:

Code:
Hibernate: insert into TB_OPERACION (ASUNTO, FECHA_FIN_OPERACION, FECHA_INICIO_OPERACION, RESULTADO, USUARIO, TIPO, ID_OPERACION) values (?, ?, ?, ?, ?, 'PeticionCambioEstado', ?)

Hibernate: insert into TB_OP_PETICION (ESTADO, ID_OPERACION) values (?, ?)

Hibernate: insert into TB_OP_PETICION (CE_COMENTARIO, CE_NUEVO_ESTADO, ID_OPERACION) values (?, ?, ?)



Can someone tell me if this mapping approach for inheritance is valid? If yes, what am I doing wrong?


Thank you!


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.