Convert Serie and SeriePunkt from data class to regular class, implement manual copy, equals, hashCode, and toString methods for JPA compliance, adjust column mappings, and add Flyway migration for database schema creation.
This commit is contained in:
+48
-10
@@ -5,7 +5,7 @@ import java.util.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "serien")
|
||||
data class Serie(
|
||||
class Serie(
|
||||
@Id
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
|
||||
@@ -16,10 +16,10 @@ data class Serie(
|
||||
val beschreibung: String? = null,
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
@Column(name = "reglement_typ", nullable = false)
|
||||
val reglementTyp: ReglementTyp = ReglementTyp.STREICHER_NORMAL,
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "streichresultate_count", nullable = false)
|
||||
val streichresultateCount: Int = 1,
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@@ -30,7 +30,26 @@ data class Serie(
|
||||
@CollectionTable(name = "serie_bewerbe", joinColumns = [JoinColumn(name = "serie_id")])
|
||||
@Column(name = "bewerb_id")
|
||||
val bewerbIds: Set<String> = mutableSetOf()
|
||||
)
|
||||
) {
|
||||
fun copy(
|
||||
id: String = this.id,
|
||||
name: String = this.name,
|
||||
beschreibung: String? = this.beschreibung,
|
||||
reglementTyp: ReglementTyp = this.reglementTyp,
|
||||
streichresultateCount: Int = this.streichresultateCount,
|
||||
bindungstyp: Bindungstyp = this.bindungstyp,
|
||||
bewerbIds: Set<String> = this.bewerbIds
|
||||
) = Serie(id, name, beschreibung, reglementTyp, streichresultateCount, bindungstyp, bewerbIds)
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is Serie) return false
|
||||
return id == other.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = id.hashCode()
|
||||
|
||||
override fun toString(): String = "Serie(id='$id', name='$name')"
|
||||
}
|
||||
|
||||
enum class ReglementTyp {
|
||||
STREICHER_NORMAL, // z.B. 4 von 6 Wertungen zählen
|
||||
@@ -46,20 +65,20 @@ enum class Bindungstyp {
|
||||
|
||||
@Entity
|
||||
@Table(name = "serie_punkte")
|
||||
data class SeriePunkt(
|
||||
class SeriePunkt(
|
||||
@Id
|
||||
val id: String = UUID.randomUUID().toString(),
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "serie_id", nullable = false)
|
||||
val serieId: String,
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "reiter_id", nullable = false)
|
||||
val reiterId: String,
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "pferd_id", nullable = false)
|
||||
val pferdId: String,
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "bewerb_id", nullable = false)
|
||||
val bewerbId: String,
|
||||
|
||||
@Column(nullable = false)
|
||||
@@ -67,4 +86,23 @@ data class SeriePunkt(
|
||||
|
||||
@Column(nullable = false)
|
||||
val platzierung: Int
|
||||
)
|
||||
) {
|
||||
fun copy(
|
||||
id: String = this.id,
|
||||
serieId: String = this.serieId,
|
||||
reiterId: String = this.reiterId,
|
||||
pferdId: String = this.pferdId,
|
||||
bewerbId: String = this.bewerbId,
|
||||
punkte: Double = this.punkte,
|
||||
platzierung: Int = this.platzierung
|
||||
) = SeriePunkt(id, serieId, reiterId, pferdId, bewerbId, punkte, platzierung)
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is SeriePunkt) return false
|
||||
return id == other.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = id.hashCode()
|
||||
|
||||
override fun toString(): String = "SeriePunkt(id='$id', serieId='$serieId', reiterId='$reiterId', pferdId='$pferdId', bewerbId='$bewerbId', punkte=$punkte)"
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
CREATE TABLE serien (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
beschreibung TEXT,
|
||||
reglement_typ VARCHAR(50) NOT NULL,
|
||||
streichresultate_count INTEGER NOT NULL DEFAULT 0,
|
||||
bindungstyp VARCHAR(50) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE serie_bewerbe (
|
||||
serie_id VARCHAR(36) NOT NULL,
|
||||
bewerb_id VARCHAR(36) NOT NULL,
|
||||
PRIMARY KEY (serie_id, bewerb_id),
|
||||
CONSTRAINT fk_serie FOREIGN KEY (serie_id) REFERENCES serien(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE serie_punkte (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
serie_id VARCHAR(36) NOT NULL,
|
||||
reiter_id VARCHAR(36) NOT NULL,
|
||||
pferd_id VARCHAR(36) NOT NULL,
|
||||
bewerb_id VARCHAR(36) NOT NULL,
|
||||
punkte DOUBLE PRECISION NOT NULL,
|
||||
platzierung INTEGER NOT NULL,
|
||||
CONSTRAINT fk_serie_punkte FOREIGN KEY (serie_id) REFERENCES serien(id) ON DELETE CASCADE
|
||||
);
|
||||
Reference in New Issue
Block a user