Skip to content

Instantly share code, notes, and snippets.

@nosrednawall
Created May 29, 2018 16:06
Show Gist options
  • Save nosrednawall/acffa649b536037d7346be1ff109571c to your computer and use it in GitHub Desktop.
Save nosrednawall/acffa649b536037d7346be1ff109571c to your computer and use it in GitHub Desktop.
Exemplo de mapeamento @OneToMany e @manytoone bidirecional
@Entity
@Table(name = "evento")
public class Evento {
// ... Outros campos ...
@ManyToOne
@JoinColumn(name = "categoria_id")
private Categoria categoria;
// ... Outros campos e métodos ...
public Categoria getCategoria() {
return categoria;
}
}
@Entity
@Table(name = "categoria")
public class Categoria {
// ... Outros campos ...
@OneToMany(mappedBy = "categoria")
private List<Evento> eventos;
// ... Outros campos e métodos ...
public List<Evento> getEventos() {
return eventos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment