|
| 1 | +package org.apeps.firstapp.domain; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
| 4 | +import org.hibernate.annotations.Cache; |
| 5 | +import org.hibernate.annotations.CacheConcurrencyStrategy; |
| 6 | + |
| 7 | +import javax.persistence.*; |
| 8 | +import javax.validation.constraints.*; |
| 9 | +import java.io.Serializable; |
| 10 | +import java.util.HashSet; |
| 11 | +import java.util.Set; |
| 12 | +import java.util.Objects; |
| 13 | + |
| 14 | +/** |
| 15 | + * A Category. |
| 16 | + */ |
| 17 | +@Entity |
| 18 | +@Table(name = "category") |
| 19 | +@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
| 20 | +public class Category implements Serializable { |
| 21 | + |
| 22 | + private static final long serialVersionUID = 1L; |
| 23 | + |
| 24 | + @Id |
| 25 | + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") |
| 26 | + @SequenceGenerator(name = "sequenceGenerator") |
| 27 | + private Long id; |
| 28 | + |
| 29 | + @NotNull |
| 30 | + @Column(name = "name", nullable = false) |
| 31 | + private String name; |
| 32 | + |
| 33 | + @OneToMany(mappedBy = "category") |
| 34 | + @JsonIgnore |
| 35 | + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
| 36 | + private Set<Item> items = new HashSet<>(); |
| 37 | + |
| 38 | + @ManyToOne |
| 39 | + private Category parent; |
| 40 | + |
| 41 | + // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove |
| 42 | + public Long getId() { |
| 43 | + return id; |
| 44 | + } |
| 45 | + |
| 46 | + public void setId(Long id) { |
| 47 | + this.id = id; |
| 48 | + } |
| 49 | + |
| 50 | + public String getName() { |
| 51 | + return name; |
| 52 | + } |
| 53 | + |
| 54 | + public Category name(String name) { |
| 55 | + this.name = name; |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + public void setName(String name) { |
| 60 | + this.name = name; |
| 61 | + } |
| 62 | + |
| 63 | + public Set<Item> getItems() { |
| 64 | + return items; |
| 65 | + } |
| 66 | + |
| 67 | + public Category items(Set<Item> items) { |
| 68 | + this.items = items; |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + public Category addItem(Item item) { |
| 73 | + this.items.add(item); |
| 74 | + item.setCategory(this); |
| 75 | + return this; |
| 76 | + } |
| 77 | + |
| 78 | + public Category removeItem(Item item) { |
| 79 | + this.items.remove(item); |
| 80 | + item.setCategory(null); |
| 81 | + return this; |
| 82 | + } |
| 83 | + |
| 84 | + public void setItems(Set<Item> items) { |
| 85 | + this.items = items; |
| 86 | + } |
| 87 | + |
| 88 | + public Category getParent() { |
| 89 | + return parent; |
| 90 | + } |
| 91 | + |
| 92 | + public Category parent(Category category) { |
| 93 | + this.parent = category; |
| 94 | + return this; |
| 95 | + } |
| 96 | + |
| 97 | + public void setParent(Category category) { |
| 98 | + this.parent = category; |
| 99 | + } |
| 100 | + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove |
| 101 | + |
| 102 | + @Override |
| 103 | + public boolean equals(Object o) { |
| 104 | + if (this == o) { |
| 105 | + return true; |
| 106 | + } |
| 107 | + if (o == null || getClass() != o.getClass()) { |
| 108 | + return false; |
| 109 | + } |
| 110 | + Category category = (Category) o; |
| 111 | + if (category.getId() == null || getId() == null) { |
| 112 | + return false; |
| 113 | + } |
| 114 | + return Objects.equals(getId(), category.getId()); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public int hashCode() { |
| 119 | + return Objects.hashCode(getId()); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public String toString() { |
| 124 | + return "Category{" + |
| 125 | + "id=" + getId() + |
| 126 | + ", name='" + getName() + "'" + |
| 127 | + "}"; |
| 128 | + } |
| 129 | +} |
0 commit comments