Skip to content

Instantly share code, notes, and snippets.

@petyosi
Created February 12, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petyosi/84e0a2fe316f07aaad0f007e68185cea to your computer and use it in GitHub Desktop.
Save petyosi/84e0a2fe316f07aaad0f007e68185cea to your computer and use it in GitHub Desktop.
package com.aggrid.crudapp.model;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Cacheable(false)
public class Athlete {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Version()
private Long version = 0L;
private String name;
@OneToOne()
private Country country;
@JsonManagedReference
@OneToMany(cascade = CascadeType.ALL, mappedBy = "athlete", orphanRemoval = true)
private List<Result> results = new ArrayList<>();
public Athlete() {
}
public Athlete(String name, Country country, List<Result> results) {
this.name = name;
this.country = country;
this.results = results;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
public List<Result> getResults() {
return results;
}
public void setResults(List<Result> results) {
this.results = results;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Athlete athlete = (Athlete) o;
if (id != null ? !id.equals(athlete.id) : athlete.id != null) return false;
return name != null ? name.equals(athlete.name) : athlete.name == null;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Athlete{" +
"id=" + id +
", name='" + name + '\'' +
", version='" + version + '\'' +
'}';
}
}
package com.aggrid.crudapp.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Country {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Country() {
}
public Country(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Country country = (Country) o;
return id != null ? id.equals(country.id) : country.id == null;
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
@Override
public String toString() {
return "Country{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
package com.aggrid.crudapp.model;
import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.*;
@Entity
public class Result {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Version()
private Long version = 0L;
@JsonBackReference
@ManyToOne(cascade = CascadeType.ALL)
private Athlete athlete;
private int age;
private int year;
private String date;
private int gold;
private int silver;
private int bronze;
@OneToOne()
private Sport sport;
public Result() {
}
public Result(Sport sport, int age, int year, String date, int gold, int silver, int bronze) {
this.sport = sport;
this.age = age;
this.year = year;
this.date = date;
this.gold = gold;
this.silver = silver;
this.bronze = bronze;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public int getGold() {
return gold;
}
public void setGold(int gold) {
this.gold = gold;
}
public int getSilver() {
return silver;
}
public void setSilver(int silver) {
this.silver = silver;
}
public int getBronze() {
return bronze;
}
public void setBronze(int bronze) {
this.bronze = bronze;
}
public Sport getSport() {
return sport;
}
public void setSport(Sport sport) {
this.sport = sport;
}
public Athlete getAthlete() {
return athlete;
}
public void setAthlete(Athlete athlete) {
this.athlete = athlete;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Result result = (Result) o;
if (age != result.age) return false;
if (year != result.year) return false;
if (gold != result.gold) return false;
if (silver != result.silver) return false;
if (bronze != result.bronze) return false;
if (id != null ? !id.equals(result.id) : result.id != null) return false;
if (version != null ? !version.equals(result.version) : result.version != null) return false;
if (athlete != null ? !athlete.equals(result.athlete) : result.athlete != null) return false;
if (date != null ? !date.equals(result.date) : result.date != null) return false;
return sport != null ? sport.equals(result.sport) : result.sport == null;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (athlete != null ? athlete.hashCode() : 0);
result = 31 * result + age;
result = 31 * result + year;
result = 31 * result + (date != null ? date.hashCode() : 0);
result = 31 * result + gold;
result = 31 * result + silver;
result = 31 * result + bronze;
result = 31 * result + (sport != null ? sport.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Result{" +
"id=" + id +
", version=" + version +
", athlete=" + athlete +
", age=" + age +
", year=" + year +
", date='" + date + '\'' +
", gold=" + gold +
", silver=" + silver +
", bronze=" + bronze +
", sport=" + sport +
'}';
}
}
package com.aggrid.crudapp.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Sport {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Sport() {
}
public Sport(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Sport sport = (Sport) o;
return id != null ? id.equals(sport.id) : sport.id == null;
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
@Override
public String toString() {
return "Sport{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment