Consignee.java

package com.tradecloud.domain.party;

import com.tradecloud.domain.comment.Comment;
import com.tradecloud.domain.party.base.Company;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashSet;
import java.util.Set;

@Entity
@Component(value = "consignee")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Consignee")
@Table(name = "consignee", uniqueConstraints = {@UniqueConstraint(columnNames = {"name"})})
public class Consignee extends Company implements Comparable<Consignee> {

    private static final long serialVersionUID = 1L;
    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "consignee_comments",
            joinColumns = {@JoinColumn(name = "consignee_id", unique = false)},
            inverseJoinColumns = {@JoinColumn(name = "comment_id", unique = false)})
    private Set<Comment> comments = new HashSet<Comment>();

    public Set<Comment> getComments() {
        return comments;
    }

    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    @Override
    public int compareTo(Consignee consignee) {
        if (getName() != null) {
            if (getName().compareTo(consignee.getName()) != 0) {
                return getName().compareTo(consignee.getName());
            }
        }
        return 0;
    }
}