Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bean;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import javax.validation.constraints.Size;
- import org.hibernate.validator.constraints.NotEmpty;
- import com.fasterxml.jackson.annotation.JsonManagedReference;
- @Entity
- @Table(name="t_users")
- public class User {
- /**
- * identifiant de l'utilisateur
- */
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private Integer id;
- /**
- * Liste des commandes liés à l'utilisateur :
- * 1-n unidirectionnelle
- */
- @OneToMany(mappedBy="user", cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
- @JsonManagedReference
- private List<Order> orders;
- /**
- * Adresse mail (unique dans le système)
- */
- @NotEmpty(message="Le mail ne peut pas être vide")
- private String mail = null;
- /**
- * Mot de passe
- */
- @NotEmpty(message="Le mot de passe ne peut pas être vide")
- @Size(min=6 , message="Le mot de passe doit avoir au moins 6 caractères")
- private String passwd = null;
- /**
- * Nom & prénom
- */
- private String name = null;
- /**
- * Adresse de livraison
- */
- private String delivery = null;
- /**
- * Adresse de facturation
- */
- private String invoice = null;
- /**
- * Constructeur
- */
- public User() {
- this.mail = "";
- this.passwd = "";
- this.name = "";
- this.delivery = "";
- this.invoice = "";
- }
- /**
- * Constructeur avec paramètres
- * @param id : identifiant, unique dans le système
- * @param mail : unique dans le système
- * @param passwd : mot de passe, doit faire 8 caractères
- * @param name : nom & prénom
- * @param delivery : adresse de livraison
- * @param invoice : adresse de facturation
- */
- public User(Integer id, String mail, String passwd, String name, String delivery, String invoice) {
- super();
- this.id = id;
- this.mail = mail;
- this.passwd = passwd;
- this.name = name;
- this.delivery = delivery;
- this.invoice = invoice;
- }
- // ACCESSEURS
- public String getMail() {
- return mail;
- }
- public void setMail(String mail) {
- this.mail = mail;
- }
- public String getPasswd() {
- return passwd;
- }
- public void setPasswd(String passwd) {
- this.passwd = passwd;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getDelivery() {
- return delivery;
- }
- public void setDelivery(String delivery) {
- this.delivery = delivery;
- }
- public String getInvoice() {
- return invoice;
- }
- public void setInvoice(String invoice) {
- this.invoice = invoice;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public List<Order> getOrders() {
- return orders;
- }
- public void setOrders(List<Order> orders) {
- this.orders = orders;
- }
- public String toString(){
- String str = "------------ USER ---------------\n";
- str += "id : " + this.id + "\n";
- str += "mail : " + this.mail + "\n";
- str += "passwd : " + this.passwd + "\n";
- str += "name : " + this.name + "\n";
- str += "delivery : " + this.delivery + "\n";
- str += "invoice : " + this.invoice + "\n";
- if (this.orders != null)
- str += "nb commande : " + this.orders.size() + "\n";
- str += "----------------------------------\n";
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement