/* * Copyright 2004 Chris Nelson * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and limitations under the License. */ package org.tynamo.examples.simple.entities; import java.util.ArrayList; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import org.apache.commons.lang.builder.HashCodeBuilder; import org.hibernate.annotations.IndexColumn; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotNull; @Entity public class Category { private Integer id; private String description; private String name; private List<Product> products = new ArrayList<Product>(); @NotNull @Length(min = 1, max = 20) public String getDescription() { return description; } /** * @param description The description to set. */ public void setDescription(String description) { this.description = description; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getId() { return id; } /** * @param id The id to set. */ public void setId(Integer id) { this.id = id; } public String toString() { return getDescription(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Category category = (Category) o; return getId() != null ? getId().equals(category.getId()) : category.getId() == null; } @Override public int hashCode() { return (getId() != null ? getId().hashCode() : 0); } public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToMany @JoinColumn(name = "CATEGORY_ID") @IndexColumn(name = "PRODUCT_INDEX") public List<Product> getProducts() { return products; } /** * @param products The products to set. */ public void setProducts(List<Product> products) { this.products = products; } }