add onetomany

This commit is contained in:
Valentin CZERYBA 2023-01-05 20:51:27 +01:00
parent 50db0ab1f2
commit d42dc014b6
2 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package com.covas.Entity; package com.covas.Entity;
import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.UUID; import java.util.UUID;
@ -8,8 +9,8 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.OneToOne;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -19,7 +20,7 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
@Entity @Entity
@Table(name = "publisher") @Table(name = "publisher")
public class PublisherEntity extends PanacheEntityBase { public class PublisherEntity extends PanacheEntityBase implements Serializable {
@Id @Id
@Column(name = "id") @Column(name = "id")
@GeneratedValue(generator = "UUID") @GeneratedValue(generator = "UUID")
@ -32,7 +33,7 @@ public class PublisherEntity extends PanacheEntityBase {
@Column(nullable = false) @Column(nullable = false)
public LocalDateTime updated_at; public LocalDateTime updated_at;
@OneToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "users_id", referencedColumnName = "id") @JoinColumn(name = "users_id", referencedColumnName = "id")
public UsersEntity users; public UsersEntity users;
} }

View File

@ -1,7 +1,9 @@
package com.covas.Entity; package com.covas.Entity;
import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
@ -10,8 +12,8 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.OneToOne;
import com.covas.Classes.Hash; 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.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") @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 @Id
@Column(name = "id") @Column(name = "id")
@GeneratedValue(generator = "UUID") @GeneratedValue(generator = "UUID")
@ -72,8 +74,8 @@ public class UsersEntity extends PanacheEntityBase {
public String description; public String description;
@OneToOne(mappedBy = "users") @OneToMany(mappedBy = "users")
public PublisherEntity publisher; public Collection<PublisherEntity> publisher;
public static UsersEntity findByPseudo(String pseudo){ public static UsersEntity findByPseudo(String pseudo){
return find("pseudo", pseudo).firstResult(); return find("pseudo", pseudo).firstResult();