Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hr.softwarecity.osijek.model; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonManagedReference; import java.io.Serializable; import java.util.List; import javax.persistence.*; /** * * @author Leon Palai * Class Address that represents location where people lives. Created in purpose to show Many to Many * mapping. This side is implemented as owning side of relation. */ @Entity @Table(name = "address") public class Address implements Serializable { @Id @GeneratedValue @Column(name = "id_address") private long idAddress; @Column(name = "location") private String location; @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable(name = "lives", joinColumns = { @JoinColumn(name = "id_address", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_person", nullable = false, updatable = false) }) @JsonManagedReference private List<Person> residents; public List<Person> getResidents() { return residents; } public void setResidents(List<Person> residents) { this.residents = residents; } public long getIdAddress() { return idAddress; } public void setIdAddress(long idAddress) { this.idAddress = idAddress; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } }