The Entites
Club: one to many
Facility: many to one
in this example the relation will be held in a separated table,
ClubTable.java
@Entity @Table(name = "club_table") public class ClubTable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name", nullable = false) private String name; @Column(name = "latitude") private String latitude; @Column(name = "longitude") private String longitude; @Column(name = "openingDate") private Date openingDate; @Column(name = "weekdaysOpeningTime") private String weekdaysOpeningTime; @Column(name = "weekdaysClosingTime") private String weekdaysClosingTime; @Column(name = "weekendOpeningTime") private String weekendOpeningTime; @Column(name = "weekendClosingTime") private String weekendClosingTime; @Column(name = "imagesUrl") private String imagesUrl; @Column(name = "email") private String email; @Column(name = "monthlyProgramUrl") private String monthlyProgramUrl; @Column(name = "address") private String address; @Column(name = "groupCode") private String groupCode; @Column(name = "legacyId") private Long legacyId; @OneToMany(cascade = CascadeType.ALL, mappedBy = "clubTable", fetch = FetchType.LAZY) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) private List<MembershipTable> memberships = Lists.newArrayList(); @Column(name = "clubcity") private String clubCity; @OneToMany(cascade = CascadeType.ALL, mappedBy="club", fetch = FetchType.LAZY) private List<MobileFacilityTable> facility; }
MobileFacilityTable.java
@Entity @Table(name = "facility") public class MobileFacilityTable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "facility_id") private Long facilityId; @ManyToOne @JoinTable(name = "club_facilities", joinColumns = { @JoinColumn(name = "facility_id") }, inverseJoinColumns = { @JoinColumn(name = "club_id") }) private ClubTable club; @Column(name = "facility_name", nullable = false) private String facilityName; @Column(name = "facility_name_eng", nullable = false) private String facilityNameEng; }
Tables
facility
club_table
club_facilities