One to Many relationship in a separated table

The Entites

Club: one to many

Facility: many to one

in this example the relation will be held in a separated table,

@Table(name = "club_table")
public class ClubTable {
	@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;


@Table(name = "facility")
public class MobileFacilityTable {
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "facility_id")
	private Long facilityId;

	@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;










Leave a Reply

Your email address will not be published. Required fields are marked *