[code]@Entity
@Table(name=“professor”)
@SequenceGenerator(name=“seq_professor”, sequenceName=“professor_idprofessor_seq”, allocationSize=1)
public class Professor extends Pessoa implements Serializable {
private static final long serialVersionUID = 8683441216699864995L;
@Column(name="idprofessor")
private int idprofessor;
@Column(name="foto")
private String foto;
private Pessoa pessoa;
public int getIdProfessor() {
return idprofessor;
}
public void setIdProfessor(int idProfessor) {
this.idprofessor = idProfessor;
}
public String getFoto() {
return foto;
}
public void setFoto(String foto) {
this.foto = foto;
}
public Pessoa getPessoa() {
return pessoa;
}
public void setPessoa(Pessoa pessoa) {
this.pessoa = pessoa;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((foto == null) ? 0 : foto.hashCode());
result = prime * result + idprofessor;
result = prime * result + ((pessoa == null) ? 0 : pessoa.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Professor other = (Professor) obj;
if (foto == null) {
if (other.foto != null)
return false;
} else if (!foto.equals(other.foto))
return false;
if (idprofessor != other.idprofessor)
return false;
if (pessoa == null) {
if (other.pessoa != null)
return false;
} else if (!pessoa.equals(other.pessoa))
return false;
return true;
}
}[/code]
[code]@Entity
@Table(name=“matricula”)
@SequenceGenerator(name=“seq_matricula”, sequenceName=“matricula_idmatricula_seq”, allocationSize=1)
public class Matricula implements Serializable{
private static final long serialVersionUID = 0L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_matricula")
@Column(name="idmatricula")
private Integer idmatricula;
@Column(name="idprofessor")
private Integer idprofessor;
@Column(name="idescola")
private Integer idescola;
@Temporal(TemporalType.DATE)
private Calendar dtmatricula;
@Column(name="situacao")
private String situacao;
public Matricula(){
}
public Matricula(Integer idmatricula,Integer idprofessor, Integer idescola,java.util.Calendar dtmatricula,String situacao){
this.idmatricula = idmatricula;
this.idprofessor = idprofessor;
this.idescola = idescola;
this.dtmatricula = dtmatricula;
this.situacao = situacao;
}
public long getIdmatricula() {
return idmatricula;
}
public void setIdmatricula(Integer idmatricula) {
this.idmatricula = idmatricula;
}
public long getIdprofessor() {
return idprofessor;
}
public void setIdprofessor(Integer idprofessor) {
this.idprofessor = idprofessor;
}
public long getIdescola() {
return idescola;
}
public void setIdescola(Integer idescola) {
this.idescola = idescola;
}
public java.util.Calendar getDtmatricula() {
return dtmatricula;
}
public void setDtmatricula(java.util.Calendar dtmatricula) {
this.dtmatricula = dtmatricula;
}
public String getSituacao() {
return situacao;
}
public void setSituacao(String situacao) {
this.situacao = situacao;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Matricula other = (Matricula) obj;
if (idmatricula == null) {
if (other.idmatricula != null)
return false;
} else if (!idmatricula.equals(other.idmatricula))
return false;
return true;
}
}[/code]
[code]@Entity
@Table(name=“pessoa”)
@SequenceGenerator(name=“seq_pessoa”, sequenceName=“pessoa_idpessoa_seq”, allocationSize=1)
public class Pessoa implements Serializable {
private static final long serialVersionUID = -7427597435054021998L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_pessoa")
@Column(name="idPessoa")
private int idPessoa;
@Column(name="nome")
private String nome;
@Column(name="sobrenome")
private String sobrenome;
@Column(name="sexo")
private EnumSexo sexo;
@Column(name="cpf")
private String cpf;
@Column(name="telefoneComercial")
private String telefoneComercial;
@Column(name="telefoneResidencial")
private String telefoneResidencial;
@Column(name="email")
private String email;
@Column(name="tipo")
private EnumTipoPessoa tipo;
public int getIdPessoa() {
return idPessoa;
}
public void setIdPessoa(int idPessoa) {
this.idPessoa = idPessoa;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSobrenome() {
return sobrenome;
}
public void setSobrenome(String sobrenome) {
this.sobrenome = sobrenome;
}
public EnumSexo getSexo() {
return sexo;
}
public void setSexo(EnumSexo sexo) {
this.sexo = sexo;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getTelefoneComercial() {
return telefoneComercial;
}
public void setTelefoneComercial(String telefoneComercial) {
this.telefoneComercial = telefoneComercial;
}
public String getTelefoneResidencial() {
return telefoneResidencial;
}
public void setTelefoneResidencial(String telefoneResidencial) {
this.telefoneResidencial = telefoneResidencial;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public EnumTipoPessoa getTipoPessoa() {
return tipo;
}
public void setTipoPessoa(EnumTipoPessoa tipo) {
this.tipo = tipo;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cpf == null) ? 0 : cpf.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + idPessoa;
result = prime * result + ((nome == null) ? 0 : nome.hashCode());
result = prime * result + ((sexo == null) ? 0 : sexo.hashCode());
result = prime * result
+ ((sobrenome == null) ? 0 : sobrenome.hashCode());
result = prime
* result
+ ((telefoneComercial == null) ? 0 : telefoneComercial
.hashCode());
result = prime
* result
+ ((telefoneResidencial == null) ? 0 : telefoneResidencial
.hashCode());
result = prime * result
+ ((tipo == null) ? 0 : tipo.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pessoa other = (Pessoa) obj;
if (cpf == null) {
if (other.cpf != null)
return false;
} else if (!cpf.equals(other.cpf))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (idPessoa != other.idPessoa)
return false;
if (nome == null) {
if (other.nome != null)
return false;
} else if (!nome.equals(other.nome))
return false;
if (sexo != other.sexo)
return false;
if (sobrenome == null) {
if (other.sobrenome != null)
return false;
} else if (!sobrenome.equals(other.sobrenome))
return false;
if (telefoneComercial == null) {
if (other.telefoneComercial != null)
return false;
} else if (!telefoneComercial.equals(other.telefoneComercial))
return false;
if (telefoneResidencial == null) {
if (other.telefoneResidencial != null)
return false;
} else if (!telefoneResidencial.equals(other.telefoneResidencial))
return false;
if (tipo != other.tipo)
return false;
return true;
}
}[/code]
[code]public class ListaEscola {
private List<Escola> escola;
private EntityManager em;
public List<Escola> getEscola() {
return escola;
}
public void setEscola(List<Escola> escola) {
this.escola = escola;
}
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
protected EntityManager getEntityManager()
{
if (this.em == null) {
this.em = EntityManagerFactorySingleton.getInstance().createEntityManager();
}// throw new IllegalStateException("Erro");
return this.em;
}
/*public Session getSession() {
EntityManager entityManager;
return ((Session)entityManager.getDelegate());
}
public final Criteria createCriteriaExample(Entity example) {
Criteria executableCriteria = getSession().createCriteria(example.getClass());
return executableCriteria;
}*/
public List<Escola> findAll() {
Query query = getEntityManager().createQuery("select esc from Escola esc ,Matricula mat,Professor prof" +
" where mat.idprofessor = prof.idprofessor and mat.idescola = esc.idescola" +
" and mat.situacao = 'A' and prof.idprofessor = 1 order by esc.nome");
return (List<Escola>) query.getResultList();
}
}[/code]
[code]@ManagedBean(name=“MostraEsc”)
@ViewScoped
public class MostraEscolaAtiva implements Serializable{
private List<Escola> escolas;
private String nm = “Teste”;
public String getNm() {
return nm;
}
public void setNm(String nm) {
this.nm = nm;
}
public void handleToggle(ToggleEvent event) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Fieldset Toggled", "Visibility:" + event.getVisibility());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public List<Escola> getEscolas() {
if(escolas == null){
escolas = new ListaEscola().findAll();
}
return escolas;
}
public void setEscolas(List<Escola> escolas) {
this.escolas = escolas;
}
}[/code]
[code]<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name=“puMosaicoDigital”>
<properties>
<property name=“hibernate.archive.autodetection” value=“class, hbm” />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5435/Mosaico" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="eguru" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>[/code]
ACHO QUE É ISSO. O PERSISTENCE É QUE A DÚVIDA. ACHO QUE É MAPEAMENTO, MAS NÃO SEI COMO RESOLVER.