Java:
package org.mjannek.sport.buli.tables;
import java.sql.*;
import java.time.*;
import javax.persistence.*;
import org.mjannek.database.entity.*;
@Entity
@Table(name = "matches")
public class Match extends BaseEntity {
@ManyToOne
@JoinColumn(name = "seasonid", foreignKey = @ForeignKey(name = "fk_match_season"))
private Season season;
@Column(name = "matchday", nullable = false)
private Integer matchday;
@ManyToOne
@JoinColumn(name = "hometeamid", foreignKey = @ForeignKey(name = "fk_match_home_team"))
private Club homeTeam;
@ManyToOne
@JoinColumn(name = "awayteamid", foreignKey = @ForeignKey(name = "fk_match_away_team"))
private Club awayTeam;
@Column(name = "homegoals")
private Integer homeGoals;
@Column(name = "awaygoals")
private Integer awayGoals;
@Column(name = "timestamp")
private Timestamp timestamp;
@ManyToOne
@JoinColumn(name = "stadiumid", foreignKey = @ForeignKey(name = "fk_match_stadium"))
private Stadium stadium;
@Column(name = "refid")
private String refId;
@Column(name = "attendance")
private Integer attendance;
@Column(name = "link")
private String link;
@ManyToOne
@JoinColumn(name = "refassid1", foreignKey = @ForeignKey(name = "fk_match_ref_ass_1"))
private Person refAss1;
@ManyToOne
@JoinColumn(name = "refassid2", foreignKey = @ForeignKey(name = "fk_match_ref_ass_2"))
private Person refAss2;
@ManyToOne
@JoinColumn(name = "refassid3", foreignKey = @ForeignKey(name = "fk_match_ref_ass_3"))
private Person refAss3;
@ManyToOne
@JoinColumn(name = "refassid4", foreignKey = @ForeignKey(name = "fk_match_ref_ass_4"))
private Person refAss4;
@ManyToOne
@JoinColumn(name = "statusid", foreignKey = @ForeignKey(name = "fk_match_status"))
private MatchStatus status;
// No-arg constructor for JPA
public Match() {
super();
}
// Constructor for setting id
public Match(int id) {
super(id);
}
// Getters and Setters
public Season getSeason() {
return season;
}
public void setSeason(Season season) {
this.season = season;
}
public Integer getMatchday() {
return matchday;
}
public void setMatchday(Integer matchday) {
this.matchday = matchday;
}
public Club getHomeTeam() {
return homeTeam;
}
public void setHomeTeam(Club homeTeam) {
this.homeTeam = homeTeam;
}
public Club getAwayTeam() {
return awayTeam;
}
public void setAwayTeam(Club awayTeam) {
this.awayTeam = awayTeam;
}
public Integer getHomeGoals() {
return homeGoals;
}
public void setHomeGoals(Integer homeGoals) {
this.homeGoals = homeGoals;
}
public Integer getAwayGoals() {
return awayGoals;
}
public void setAwayGoals(Integer awayGoals) {
this.awayGoals = awayGoals;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public Stadium getStadium() {
return stadium;
}
public void setStadium(Stadium stadium) {
this.stadium = stadium;
}
public String getRefId() {
return refId;
}
public void setRefId(String refId) {
this.refId = refId;
}
public Integer getAttendance() {
return attendance;
}
public void setAttendance(Integer attendance) {
this.attendance = attendance;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public Person getRefAss1() {
return refAss1;
}
public void setRefAss1(Person refAss1) {
this.refAss1 = refAss1;
}
public Person getRefAss2() {
return refAss2;
}
public void setRefAss2(Person refAss2) {
this.refAss2 = refAss2;
}
public Person getRefAss3() {
return refAss3;
}
public void setRefAss3(Person refAss3) {
this.refAss3 = refAss3;
}
public Person getRefAss4() {
return refAss4;
}
public void setRefAss4(Person refAss4) {
this.refAss4 = refAss4;
}
public MatchStatus getStatus() {
return status;
}
public void setStatus(MatchStatus status) {
this.status = status;
}
}
Wie kann ich einen Unique Constraint so setzen, das ein Club pro Saison, Spieltag und MatchStatus, egal ob heim oder auswärts nur einmal vorkommen darf?
Der MatchStatus spielt eine Rolle, da ein Spiel den Status "abgebrochen" hat und es ein Wiederholungsspiel geben muss.