Hokmun wrote:
Can anybody give me description or, even better, example of it.
Thank you in advance
here's how i use it in my app:
Code:
package dominio;
import java.math.BigDecimal;
import java.util.Date;
public abstract class Contrato {
protected Long id, idDoAnterior;
private String nomeActoMedico, tipoContrato;
private String obs = "";
private Date data; // estabelece validade a partir desta data
private Date fimDeVigencia;
private BigDecimal valorContratado; // valor global
private boolean emVigencia;
// getters and setters
}
Code:
package dominio;
import java.math.BigDecimal;
import bd.InterfacePersistencia;
public class ContratoConvencao extends Contrato {
private BigDecimal pagoPelaConvencao; // comparticipaĆ§Ć£o
private BigDecimal pagoPeloUtente; // recebido
private Entidade entidade;
private Convencao convencao;
private Banco banco;
private InterfacePersistencia facade;
private ActoMedico actoMedico; // one to one
private ContratoConvencao() {}
public ContratoConvencao(String nomeActoMedico, String tipoContrato,
Entidade entidade, Convencao convencao) {
setNomeActoMedico(nomeActoMedico);
setTipoContrato(tipoContrato);
this.entidade = entidade;
this.convencao = convencao;
}
public void add(InterfacePersistencia facade) {
this.facade = facade;
}
public void actualiza() {
facade.actualiza();
}
//getters setters
@Override
public BigDecimal getValorContratado() {
return getPagoPeloUtente().add(getPagoPelaConvencao());
}
@Override
public boolean equals(Object object) {
//...
}
@Override
public int hashCode() {
//...
}
@Override
public String toString() {
//...
}
}
Code:
package dominio;
public class ContratoTecnica extends Contrato {
private Tecnica tecnica;
private ContratoTecnica() {}
public ContratoTecnica(String nomeActoMedico, String tipoContrato,
Tecnica tecnica) {
setNomeActoMedico(nomeActoMedico);
setTipoContrato(tipoContrato);
this.tecnica = tecnica;
}
@Override
public boolean equals(Object object) {
//...
}
@Override
public int hashCode() {
//...
}
@Override
public String toString() {
//...
}
}
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
package = "dominio">
<class
name = "Contrato"
table = "contrato"
discriminator-value = "contrato">
<id
name = "id"
column = "contrato_id">
<generator
class = "native" />
</id>
<discriminator
column = "heranca_contrato"
type = "string" />
<property
name = "nomeActoMedico"/>
<property
name = "tipoContrato"/>
<property
name = "obs"/>
<property
name = "data"
type = "date" />
<property
name = "fimDeVigencia"
type = "date" />
<property
name = "valorContratado">
<column
name = "valorContratado"
sql-type = "decimal(10,2)" />
</property>
<property
name = "emVigencia"
type = "boolean" />
<property
name = "idDoAnterior"
type = "long" />
<subclass
name = "ContratoParticular"
discriminator-value = "particular">
<many-to-one
name = "entidade"
column = "entidade_id"
class = "Entidade" />
</subclass>
<subclass
name = "ContratoTecnica"
discriminator-value = "tecnica">
<many-to-one
name = "tecnica"
column = "tecnica_id"
class = "Tecnica" />
</subclass>
<subclass
name = "ContratoConvencao"
discriminator-value = "convencao">
<property
name = "pagoPelaConvencao">
<column
name = "pagoPelaConvencao"
sql-type = "decimal(10,2)" />
</property>
<property
name = "pagoPeloUtente">
<column
name = "pagoPeloUtente"
sql-type = "decimal(10,2)" />
</property>
<many-to-one
name = "convencao"
column = "convencao_id"
class = "Convencao" />
<many-to-one
name = "entidade"
column = "entidade_id"
class = "Entidade" />
<one-to-one
name = "actoMedico"
class = "ActoMedico" />
<component
name = "banco"
class = "Banco">
<property
name = "nome"
type = "string"
column = "nome" />
<property
name = "nib"
type = "string"
column = "nib" />
</component>
</subclass>
</class>
</hibernate-mapping>
Hope this helps