From d42dc014b652481cfbb242e8f1d2dd91b99bf8db Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 5 Jan 2023 20:51:27 +0100 Subject: [PATCH] add onetomany --- src/main/java/com/covas/Entity/PublisherEntity.java | 7 ++++--- src/main/java/com/covas/Entity/UsersEntity.java | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/covas/Entity/PublisherEntity.java b/src/main/java/com/covas/Entity/PublisherEntity.java index f0fc80a..a79c483 100644 --- a/src/main/java/com/covas/Entity/PublisherEntity.java +++ b/src/main/java/com/covas/Entity/PublisherEntity.java @@ -1,5 +1,6 @@ package com.covas.Entity; +import java.io.Serializable; import java.time.LocalDateTime; import java.util.UUID; @@ -8,8 +9,8 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; -import javax.persistence.OneToOne; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.CascadeType; @@ -19,7 +20,7 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @Entity @Table(name = "publisher") -public class PublisherEntity extends PanacheEntityBase { +public class PublisherEntity extends PanacheEntityBase implements Serializable { @Id @Column(name = "id") @GeneratedValue(generator = "UUID") @@ -32,7 +33,7 @@ public class PublisherEntity extends PanacheEntityBase { @Column(nullable = false) public LocalDateTime updated_at; - @OneToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "users_id", referencedColumnName = "id") public UsersEntity users; } \ No newline at end of file diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 92c3af1..e8a5a14 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -1,7 +1,9 @@ package com.covas.Entity; +import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.Collection; import java.util.UUID; import javax.persistence.Column; @@ -10,8 +12,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.persistence.OneToOne; import com.covas.Classes.Hash; @@ -38,7 +40,7 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @NamedQuery(name = "Users.bySearchandStatus", query = "from UsersEntity u where (u.pseudo like :search or u.name like :search or u.firstName like :search) and u.status = :status"), @NamedQuery(name = "Users.bySearchandRolesandStatus", query = "from UsersEntity u where (u.pseudo like :search or u.name like :search or u.firstName like :search) and u.roles = :roles and u.status = :status") }) -public class UsersEntity extends PanacheEntityBase { +public class UsersEntity extends PanacheEntityBase implements Serializable { @Id @Column(name = "id") @GeneratedValue(generator = "UUID") @@ -72,8 +74,8 @@ public class UsersEntity extends PanacheEntityBase { public String description; - @OneToOne(mappedBy = "users") - public PublisherEntity publisher; + @OneToMany(mappedBy = "users") + public Collection publisher; public static UsersEntity findByPseudo(String pseudo){ return find("pseudo", pseudo).firstResult();