@Entity @Table (name = "PRODUCTS") @XmlRootElement @NamedQueries ({@NamedQuery (name = "Product.findAll", query = "SELECT p FROM Product p"), @NamedQuery (name = "Product.findById",query = "ВЫБРАТЬ p ИЗ ПРОДУКТА p, ГДЕ p.id =: id"), @NamedQuery (name = "Product.findByName", query = "ВЫБРАТЬ p ИЗ ПРОДУКТА p, ГДЕ p.name подобно: name"), @NamedQuery (name = "Product.findByPrice", query = "SELECT p FROM продукта p WHERE p.price =: price"), @NamedQuery (name = "Product.findByBestBefore", query = "SELECT p FROM продукта p, ГДЕ p.bestBefore =: bestBefore "), @NamedQuery (name =" Product.findByVersion ", запрос =" ВЫБРАТЬ p ИЗ ПРОДУКТА p ГДЕ p.version =: версия "), @NamedQuery (name =" Product.findTotal ", query ="SELECT count (p.id), sum (p.price) ОТ продукта p, ГДЕ p.id in: ids ")})
открытый класс Продукт реализует Сериализуемый {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@SequenceGenerator( name="pidGen", sequenceName="PID_SEQ", allocationSize=1 )
@GeneratedValue( strategy=SEQUENCE, generator="pidGen" )
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 3, max = 40, message="{prod.name}")
private String name;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Basic(optional = false)
@NotNull
@Max( value=1000, message="{prod.price.max}")
@Min( value=1, message="{prod.price.min}")
private BigDecimal price;
@Column(name = "BEST_BEFORE")
@Temporal(TemporalType.DATE)
//private Date bestBefore;
private LocalDate bestBefore;
@Version
private Integer version;
public Product() {
}
public Product(Integer id) {
this.id = id;
}
public Product(Integer id, String name, BigDecimal price) {
this.id = id;
this.name = name;
this.price = price;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Product)) {
return false;
}
Product other = (Product) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
}