Como fazer herança com Hibernate Annotations?

2 respostas
Fernando_Romulo_da_S

Ola galera…
alguem pode me ajudar a fazer a herança, principalmente uma classe para cada tabela…

eu tenho as seguintes classes…

Pessoa…

@Entity
@Table(name = "Pessoa", catalog = "Banco", uniqueConstraints = {})
public class Pessoa implements Serializable
{

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(unique = true, nullable = false)
	private int id;

	// nao pode ser null tamanho
	@Column(nullable = false, length = 45)
	private String nome;

	// / pode ser null pode inserir pode atualizar tamanho
	@Column(nullable = true, insertable = true, updatable = true, length = 45)
	private String telefone;

	@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	private Endereco endereco;
....
}

e Aluno…

@Entity
@Table(name = "Professor", catalog = "Banco", uniqueConstraints = {})
public class Professor extends Pessoa
{
	
	private static final long serialVersionUID = 1L;
	
	@Column(nullable = false, length = 45)
	private String titulo;
	
	@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="Professor")
	private Set<Turma> turma = new HashSet<Turma>(0);

valews…

2 Respostas

J

Faz assim cara coloca essa anotação:
@Inheritance(strategy = InheritanceType.JOINED)
na sua classe pessoa, dai o ID da tabela pessoa vai para a outra tabela também.

Estou usando assim.

Que a força esteja com vc.
T+

Fernando_Romulo_da_S

OW Funcionou aqui!!!
Valews…

demorei um pouco mas agradeci rsrsrs…

ate +…

Criado 23 de agosto de 2006
Ultima resposta 29 de ago. de 2006
Respostas 2
Participantes 2