Created
August 10, 2013 06:35
-
-
Save yareally/6199353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.util.*; | |
import javax.persistence.*; | |
import play.db.ebean.*; | |
import play.data.format.Formats.*; | |
import play.data.format.Formatters.*; | |
import play.data.validation.Constraints.*; | |
import play.data.validation.Validation.*; | |
import play.data.validation.ValidationError.*; | |
import play.libs.F; | |
import javax.validation.Valid; | |
/** | |
* @author Wes Lanning | |
* @version 2013-08-01 | |
*/ | |
@Entity | |
@Table(name = "product") | |
public class Product extends Model | |
{ | |
public static Model.Finder<Long, Product> find = new Model.Finder<>(Long.class, Product.class); | |
@Valid | |
@ManyToOne(cascade = CascadeType.ALL) | |
@OrderBy("name") | |
@JoinColumn(name = "cat_id") | |
public Category category; | |
@Valid | |
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) | |
@MapKeyEnumerated(EnumType.ORDINAL) | |
@JoinColumn(name = "id") | |
public Map<Image.ImageType, Image> images; // EnumMap, key = type of image | |
@Valid | |
@ManyToOne(cascade = CascadeType.ALL) | |
@OrderBy("name") | |
@JoinColumn(name = "man_id") | |
public Manufacturer manufacturer; | |
@Temporal(TemporalType.TIMESTAMP) | |
public Date dateAdded; | |
@Required(message = "Please enter a product description") | |
public String description; | |
@Id | |
@GeneratedValue | |
public Long id; | |
@Required(message = "Please enter a product name") | |
@Column(unique = true) | |
public String name; | |
@Required(message = "Please enter a product price.") | |
@Min(value = 0, message = "Please enter a non-negative price") | |
@Column(scale = 2) | |
public Double price; | |
@Required(message = "Please enter a product quantity") | |
@Min(value = 0, message = "Please enter a product quantity greater than zero") | |
public Integer quantity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment