I'm Brazilian, thus most of the terms in the code are in portuguese.
The first is the base class
Pessoa ( People in english ):
Code:
package br.netsoft.beans;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.validator.NotEmpty;
import br.netsoft.triggers.annotation.Property;
import br.netsoft.triggers.annotation.Trigger;
import br.netsoft.triggers.annotation.Triggers;
import static org.hibernate.annotations.GenerationTime.INSERT;
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Pessoa implements Serializable {
private static final long serialVersionUID = 6618459058833565385L;
private Integer id;
private Date dataCadastro;
private String nome;
private Bairro bairro;
private Cidade cidade;
private String endereco;
private String telefone;
private String ramal;
private String fax;
private String cep;
private Zona zona;
private TipoPessoa tipoPessoa;
public Pessoa() {
}
// ... only getters and setters (omited for brevity)
}
The second is the class
Funcionario ( Employee in english ):
Code:
package br.netsoft.beans;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.ParamDef;
import org.hibernate.validator.NotNull;
import br.netsoft.validation.annotations.ValorPositivo;
@Entity @org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@FilterDef(name="procurarFuncionarioPorTipo",parameters={@ParamDef(name="tipoFuncionario",
type="string")})
@Filter(name="procurarFuncionarioPorTipo",condition=":tipoFuncionario = tipo")
public class Funcionario extends Pessoa {
private static final long serialVersionUID = 657635050835720817L;
private Loja loja;
private Date dataAdmissao;
private Double comissao=0d;
private TipoFuncionario tipo = TipoFuncionario.Administrativo;
private Double comissaoPre=0d;
private Double comissaoAtacado=0d;
private Date dataDemissao;
private String grauInstrucao;
private PIS pis;
private String funcao;
private String naturalidade;
private Double salario=0d;
private Date horarioInicio;
private Date horarioFinal;
private Date horarioInicioSabado;
private Date horarioFinalSabado;
private CarteiraTrabalho ctps;
private EstadoCivil estadoCivil;
private Date dataNascimento;
private TituloEleitor titulo;
private String cpf;
private RG rg;
public Funcionario() {
super();
pis = new PIS();
}
// ... only getters and setters (omited for brevity)
}
The TipoFuncionario enum:
Code:
package br.netsoft.beans;
public enum TipoFuncionario {
Vendedor,Balconista,Entregador,Tecnico, Cobrador, Indicador,Motorista,Administrativo,Todos
}
Thus, when I will use the filter, i do ...
Code:
Session s = factory.openSession();
s.enableFilter("procurarFuncionarioPorTipo").setParameter("tipoFuncionario",TipoFuncionario.Vendedor.name()));
List employees = s.createCriteria(Funcionario.class).list();
for(Object o: employees)
System.out.println(o);
... and the for loop show all records of Funcionario in the database