2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jshopcore.model.category;
19 import javax.persistence.Basic;
20 import javax.persistence.CascadeType;
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.JoinColumn;
27 import javax.persistence.OneToOne;
28 import javax.persistence.Table;
33 * @author Roland Haeder<roland@mxchange.org>
35 @Entity (name = "category")
36 @Table (name = "category")
37 public class ProductCategory implements Category {
42 private static final long serialVersionUID = 21_458_945_712_659L;
45 * Id number of category
48 @GeneratedValue (strategy = GenerationType.IDENTITY)
49 @Column (name = "category_id", length = 20, nullable = false)
50 private Long categoryId;
55 @Basic (optional = false)
56 @Column (name = "category_title", length = 100, nullable = false, unique = true)
57 private String categoryTitle;
62 @JoinColumn (name = "parent_id")
63 @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH)
64 private Category parentCategory;
67 * Constructor which accepts all database fields
69 * @param categoryId Id number of database record
70 * @param categoryTitle Category categoryTitle
71 * @param parentCategory Parent category
73 public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) {
75 this.categoryId = categoryId;
76 this.categoryTitle = categoryTitle;
77 this.parentCategory = parentCategory;
83 public ProductCategory () {
87 public void copyAll (final Category category) {
89 this.setParentCategory(category.getParentCategory());
90 this.setCategoryTitle(category.getCategoryTitle());
94 public Long getCategoryId () {
95 return this.categoryId;
99 public void setCategoryId (final Long categoryId) {
100 this.categoryId = categoryId;
104 public String getCategoryTitle () {
105 return this.categoryTitle;
109 public void setCategoryTitle (final String categoryTitle) {
110 this.categoryTitle = categoryTitle;
114 public Category getParentCategory () {
115 return this.parentCategory;
119 public void setParentCategory (final Category parentCategory) {
120 this.parentCategory = parentCategory;