relations between entities created

This commit is contained in:
Marcin Hutek 2023-12-28 15:33:33 +01:00
parent 7f2c44cd59
commit b6063cd0b9
5 changed files with 32 additions and 0 deletions

View File

@ -37,6 +37,11 @@
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.28.0</version>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,9 @@
package org.example;
import jakarta.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name="category")
public class FilmCategoryModel {
@ -31,6 +34,9 @@ public class FilmCategoryModel {
this.filmCategory = filmCategory;
}
@OneToMany(mappedBy = "category_id", fetch = FetchType.LAZY)
private Set<FilmInfoModel> filmInfoSet = new HashSet<>();
@Override
public String toString() {
return "Category{" +

View File

@ -86,6 +86,18 @@ public class FilmInfoModel {
this.filmCategory = filmCategory;
}
@ManyToOne
@JoinColumn(name = "language_id")
private FilmLanguageModel filmLanguageModel;
@ManyToOne
@JoinColumn(name = "category_id")
private FilmCategoryModel filmCategoryModel;
@OneToOne
@JoinColumn(name = "film_id")
private FilmModel film;
@Override
public String toString() {
return "FilmInfo{" +

View File

@ -1,6 +1,9 @@
package org.example;
import jakarta.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name="language")
public class FilmLanguageModel {
@ -31,6 +34,9 @@ public class FilmLanguageModel {
this.filmLanguage = filmLanguage;
}
@OneToMany(mappedBy = "language_id", fetch = FetchType.LAZY)
private Set<FilmInfoModel> filmInfoSet = new HashSet<>();
@Override
public String toString() {
return "Language{" +

View File

@ -31,6 +31,9 @@ public class FilmModel {
this.filmTitle = filmTitle;
}
@OneToOne(mappedBy = "film", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private FilmInfoModel filmInfo;
@Override
public String toString() {
return "Film{" +