-->
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.  [ 3 posts ] 
Author Message
 Post subject: mapping inner classes
PostPosted: Tue Mar 08, 2005 7:44 pm 
Newbie

Joined: Tue Jan 25, 2005 11:53 am
Posts: 8
Hi,

I have this class:


Code:
public class Periodo extends Entidad {
    private String codigo;
    private Date desde;
    private Date hasta;
    private transient Ambar ambar;
   
    public Periodo() {}
   
    public Periodo(String codigo, Date desde, Date hasta) {
        setCodigo(codigo);
        setDesde(desde);
        setHasta(hasta);
    }

    private EstadoPeriodo estadoActual = new EstadoPendiente();
    public void activar() {
       estadoActual = estadoActual.activar();
    }
    public void emitir() {
       estadoActual = estadoActual.emitir();
    }
    public String getEstado() {
       return estadoActual.toString();
    }

    public abstract class EstadoPeriodo {
       public EstadoPeriodo activar() throws IllegalStateException {
          throw new IllegalStateException("activar: Estado de periodo inválido");
       }
       public EstadoPeriodo emitir() throws IllegalStateException {
          throw new IllegalStateException("activar: Estado de periodo inválido");
       }
       public abstract String toString();
    }
    private class EstadoPendiente extends EstadoPeriodo {
       public EstadoPeriodo activar() throws IllegalStateException {
          return new EstadoActivo();
       }
       public String toString() { return "Pendiente"; }
    }
    private class EstadoActivo extends EstadoPeriodo {
       public EstadoPeriodo emitir() throws IllegalStateException {
          return new EstadoEmitido();
       }
       public String toString() { return "Activo"; }
    }
    private class EstadoEmitido extends EstadoPeriodo {
       public String toString() { return "Emitido"; }
    }


, the table:
Code:
CREATE SEQUENCE sc_periodo;
CREATE TABLE periodo (
    id      INTEGER     NOT NULL,
    codigo  VARCHAR(16) NOT NULL,
    desde   DATE        NOT NULL,
    hasta   DATE        NOT NULL,
    estado  CHAR(1)   NOT NULL CHECK(estado IN('A', 'P', 'E')),--Activo, Pendiente, Emitido
    PRIMARY KEY(id),
    UNIQUE(codigo),
    CHECK(desde < hasta)
);


and the mapping:

Code:
   <class name="ambar.modelo.periodo.Periodo" table="periodo">
      <id name="id" column="id" unsaved-value="-1">
         <generator class="sequence">
                <param name="sequence">sc_periodo</param>
            </generator>
      </id>
      <property name="codigo" column="codigo"/>
      <property name="desde" column="desde"/>
      <property name="hasta" column="hasta"/>
   </class>


as you can see the mapping is incomplete. How should i map the classes inherited from EstadoPeriodo.

Reading the reference, i understand i use component. but i just don´t get how can i do this.

thanks a lot, in advance for any help,

Juan Romero


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 7:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 8:07 pm 
Newbie

Joined: Tue Jan 25, 2005 11:53 am
Posts: 8
Thanks for your answer Michael.

So, what do you think should i do?? EstadoPeriodo and sons as outer classes??

did i make a design mistake with this classes as inner classes?

Juan Romero


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.