/**
 * Most of the code in the Qalingo project is copyrighted Hoteia and licensed
 * under the Apache License Version 2.0 (release version 0.7.0)
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *                   Copyright (c) Hoteia, 2012-2013
 * http://www.hoteia.com - http://twitter.com/hoteia - contact@hoteia.com
 *
 */
package fr.hoteia.qalingo.core.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="TECO_RETAILER_CUSTOMER_COMMENT")
public class RetailerCustomerComment extends AbstractAddress implements Serializable {

	/**
	 * Generated UID
	 */
    private static final long serialVersionUID = 1424510557043858148L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID", nullable=false)
	private Long id;
	
	@Column(name="COMMENT")
    private String comment;

	@Column(name="RETAILER_CUSTOMER_COMMENT_ID")
	private Long retailerCustomerCommentId;
	
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name="CUSTOMER_ID")
	private Customer customer;

	@Column(name="RETAILER_ID")
	private Long retailerId;
	
	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name="RETAILER_ID")
	private Set<RetailerCustomerComment> customerComments = new HashSet<RetailerCustomerComment>(); 
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="DATE_CREATE")
	private Date dateCreate;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="DATE_UPDATE")
	private Date dateUpdate;
	
	public RetailerCustomerComment() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public String getComment() {
    	return comment;
    }

	public void setComment(String comment) {
    	this.comment = comment;
    }

	public Long getRetailerCustomerCommentId() {
    	return retailerCustomerCommentId;
    }

	public void setRetailerCustomerCommentId(Long retailerCustomerCommentId) {
    	this.retailerCustomerCommentId = retailerCustomerCommentId;
    }

	public Customer getCustomer() {
    	return customer;
    }

	public void setCustomer(Customer customer) {
    	this.customer = customer;
    }

	public Long getRetailerId() {
	    return retailerId;
    }
	
	public void setRetailerId(Long retailerId) {
	    this.retailerId = retailerId;
    }

	public Set<RetailerCustomerComment> getCustomerComments() {
    	return customerComments;
    }

	public void setCustomerComments(Set<RetailerCustomerComment> customerComments) {
    	this.customerComments = customerComments;
    }

	public Date getDateCreate() {
    	return dateCreate;
    }

	public void setDateCreate(Date dateCreate) {
    	this.dateCreate = dateCreate;
    }

	public Date getDateUpdate() {
    	return dateUpdate;
    }

	public void setDateUpdate(Date dateUpdate) {
    	this.dateUpdate = dateUpdate;
    }

	@Override
    public int hashCode() {
	    final int prime = 31;
	    int result = 1;
	    result = prime * result + ((comment == null) ? 0 : comment.hashCode());
	    result = prime * result + ((customerComments == null) ? 0 : customerComments.hashCode());
	    result = prime * result + ((id == null) ? 0 : id.hashCode());
	    result = prime * result + ((retailerCustomerCommentId == null) ? 0 : retailerCustomerCommentId.hashCode());
	    result = prime * result + ((retailerId == null) ? 0 : retailerId.hashCode());
	    return result;
    }

	@Override
    public boolean equals(Object obj) {
	    if (this == obj)
		    return true;
	    if (obj == null)
		    return false;
	    if (getClass() != obj.getClass())
		    return false;
	    RetailerCustomerComment other = (RetailerCustomerComment) obj;
	    if (comment == null) {
		    if (other.comment != null)
			    return false;
	    } else if (!comment.equals(other.comment))
		    return false;
	    if (customerComments == null) {
		    if (other.customerComments != null)
			    return false;
	    } else if (!customerComments.equals(other.customerComments))
		    return false;
	    if (id == null) {
		    if (other.id != null)
			    return false;
	    } else if (!id.equals(other.id))
		    return false;
	    if (retailerCustomerCommentId == null) {
		    if (other.retailerCustomerCommentId != null)
			    return false;
	    } else if (!retailerCustomerCommentId.equals(other.retailerCustomerCommentId))
		    return false;
	    if (retailerId == null) {
		    if (other.retailerId != null)
			    return false;
	    } else if (!retailerId.equals(other.retailerId))
		    return false;
	    return true;
    }

	@Override
    public String toString() {
	    return "RetailerCustomerComment [id=" + id + ", comment=" + comment + ", retailerCustomerCommentId=" + retailerCustomerCommentId + ", retailerId=" + retailerId
	            + ", customerComments=" + customerComments + "]";
    }
	
}
@@ -1520,32 +1520,33 @@
 AGER, cascade = 
+%7B
 CascadeType.ALL)
@@ -1533,35 +1533,58 @@
  = %7BCascadeType.
-ALL
+MERGE, CascadeType.DETACH%7D
 )%0D%0A    @JoinColu

fix cascade