Beleza vamos lá então!
Classe Aluno:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package models;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
/**
*
* @author reinildes
*/
@Entity
public class Aluno extends Pessoa {
@ManyToOne
private Responsavel responsavel;
@ManyToMany(mappedBy = "alunos")
private List<Curso> cursos;
private String diaCurso;
private String horarioCurso;
public Aluno() {
}
public Responsavel getResponsavel() {
return responsavel;
}
public void setResponsavel(Responsavel responsavel) {
this.responsavel = responsavel;
}
public List<Curso> getCursos() {
return cursos;
}
public void setCursos(List<Curso> cursos) {
this.cursos = cursos;
}
public String getDiaCurso() {
return diaCurso;
}
public void setDiaCurso(String diaCurso) {
this.diaCurso = diaCurso;
}
public String getHorarioCurso() {
return horarioCurso;
}
public void setHorarioCurso(String horarioCurso) {
this.horarioCurso = horarioCurso;
}
public Aluno(Responsavel responsavel, List<Curso> cursos) {
this.responsavel = responsavel;
this.cursos = cursos;
}
public Aluno(Responsavel responsavel, List<Curso> cursos, String nome, String rg, String cpf, Date dataNascimento, String telefone, String email) {
super(nome, rg, cpf, dataNascimento, telefone, email);
this.responsavel = responsavel;
this.cursos = cursos;
}
}
Classe Curso:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package models;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.validation.constraints.NotNull;
/**
*
* @author reinildes
*/
@Entity
public class Curso implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@NotNull(message="Erradp")
private String nome;
@NotNull
private String descricao;
private int numeroDeAulas;
private int mesesDuracao;
@ManyToMany
private List <Aluno> alunos;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public int getNumeroDeAulas() {
return numeroDeAulas;
}
public void setNumeroDeAulas(int numeroDeAulas) {
this.numeroDeAulas = numeroDeAulas;
}
public int getMesesDuracao() {
return mesesDuracao;
}
public void setMesesDuracao(int mesesDuracao) {
this.mesesDuracao = mesesDuracao;
}
public List<Aluno> getAlunos() {
return alunos;
}
public void setAlunos(List<Aluno> alunos) {
this.alunos = alunos;
}
}
Como pode ver a classe aluno extend a classe pessoa:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package models;
import br.com.caelum.stella.bean.validation.CPF;
import com.sun.istack.internal.NotNull;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author reinildes
*/
@MappedSuperclass
public class Pessoa implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String nome;
private String rg;
@CPF
private String cpf;
@Temporal(TemporalType.DATE)
private Date dataNascimento;
private String telefone;
private String email;
private String detalhes;
public Pessoa() {
}
public Pessoa(String nome, String rg, String cpf, Date dataNascimento, String telefone, String email) {
this.nome = nome;
this.rg = rg;
this.cpf = cpf;
this.dataNascimento = dataNascimento;
this.telefone = telefone;
this.email = email;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getRg() {
return rg;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public Date getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDetalhes() {
return detalhes;
}
public void setDetalhes(String detalhes) {
this.detalhes = detalhes;
}
}
Abaixo print do db:
[img]http://imageshack.us/photo/my-images/855/capturadetelade20130226.png/[/img]
Link: http://imageshack.us/photo/my-images/855/capturadetelade20130226.png/
Estou usando o hibernate que vem no netbeans 7.2, acredito que seja o 3.