/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jpa.demo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PostLoad;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Pattern;

/**
 *
 * @author Administrator
 */
@Entity
@NamedQuery(name="getCustomer", query="select c FROM Customer c  WHERE c.id=?1")
public class Customer {
@Id @GeneratedValue
private Long id;
private String Name;
@Pattern(regexp = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message = "{invalid.email}")
private String email;
private String phoneNumber;

    public Long getId() {
        return id;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
    @OneToOne( cascade=CascadeType.PERSIST ,  fetch= FetchType.LAZY)
private Address address;
// Constructors, getters, setters

    public Customer() {
    }
@OneToOne
private Discount discount;
@OneToMany( mappedBy="customerid", fetch = FetchType.EAGER)

private List<CustomerOrder> orders;
 public String toString() {
    return "Customer id: " + getId() + " name: " + getName() + " email: " + getEmail()+" phonenumber:"+getPhoneNumber();
  }
 @Temporal(TemporalType.DATE)
 private Date lastvisted;

    public Date getLastvisted() {
        return lastvisted;
    }

    public void setLastvisted(Date lastvisted) {
        this.lastvisted = lastvisted;
    }
    
@PostLoad
    public void setLastvisted() {
   
        this.lastvisted =new Date();
    }

}
