*/
@Entity (name = "category")
@Table (name = "category")
-public class ProductCategory implements Category, Comparable<Category> {
+public class ProductCategory implements Category {
/**
* Serial number
*/
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
- @Column (name = "category_id", length = 20, nullable = false)
+ @Column (name = "category_id", nullable = false)
private Long categoryId;
/**
* Parent category
*/
@JoinColumn (name = "parent_id")
- @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.MERGE)
+ @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
private Category parentCategory;
/**
* Constructor which accepts all database fields
* <p>
- * @param categoryId Id number of database record
- * @param categoryTitle Category categoryTitle
+ * @param categoryId Id number of database record
+ * @param categoryTitle Category categoryTitle
* @param parentCategory Parent category
*/
public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
}
@Override
- public int compareTo (final Category category) {
- // category should not be null
- if (null == category) {
- throw new NullPointerException("category is null"); //NOI18N
+ public void copyAll (final Category category) {
+ // Copy all data
+ this.setParentCategory(category.getParentCategory());
+ this.setCategoryTitle(category.getCategoryTitle());
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (this == object) {
+ return true;
+ } else if (null == object) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
}
- // Is the categoryId the same?
- if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
- // Same categoryId, means same category
- return 0;
- } else if (this.getCategoryId() > category.getCategoryId()) {
- // This categoryId is larger than compared to
- return -1;
+ final Category other = (Category) object;
+
+ if (!Objects.equals(this.getCategoryTitle(), other.getCategoryTitle())) {
+ return false;
+ } else if (!Objects.equals(this.getCategoryId(), other.getCategoryId())) {
+ return false;
}
- // The other categoryId is larger
- return 1;
+ return true;
}
@Override
- public void copyAll (final Category category) {
- // Copy all data
- this.setParentCategory(category.getParentCategory());
- this.setCategoryTitle(category.getCategoryTitle());
+ public int hashCode () {
+ int hash = 7;
+ hash = 13 * hash + Objects.hashCode(this.getCategoryId());
+ hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());
+ return hash;
}
@Override
public void setParentCategory (final Category parentCategory) {
this.parentCategory = parentCategory;
}
+
}