0% found this document useful (0 votes)
27 views

Hibernate&struts 2

This document contains the Java code for a Product class. The Product class defines the attributes and methods for a product entity, including an ID, name, price, stock level, owner, and sales. It uses JPA annotations for entity mapping and relationships with other classes like User and Sales.

Uploaded by

Fabiano Farah
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Hibernate&struts 2

This document contains the Java code for a Product class. The Product class defines the attributes and methods for a product entity, including an ID, name, price, stock level, owner, and sales. It uses JPA annotations for entity mapping and relationships with other classes like User and Sales.

Uploaded by

Fabiano Farah
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Product.

java

package br.hibernate.beans;

import java.io.Serializable;

@Entity
@Table(name="product")
public class Product implements Serializable {

private static final long serialVersionUID = 1L;

public Product() {}

@Id
@Column(name="id")
@GeneratedValue
private Integer id;

@Column(name="name")
private String name;

@Column(name="prince")
private double prince;

@Column(name="stock")
private int stock = 1;

@ManyToOne
@JoinColumn(name="ID_OWNER",referencedColumnName="id")
private User owner;

@OneToMany(mappedBy="product",cascade = CascadeType.ALL, fetch=FetchType.LAZY)


private List<Sales> sales;

public Integer getId() {


return id;
}

public void setId(Integer id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public double getPrince() {


return prince;
}

public void setPrince(double prince) {


this.prince = prince;
}

public int getStock() {


return stock;
}

public void setStock(int stock) {


this.stock = stock;
}

Page 1
Product.java

public User getOwner() {


return owner;
}

public void setOwner(User owner) {


this.owner = owner;
}

public List<Sales> getSales() {


return sales;
}

public void setSales(List<Sales> sales) {


this.sales = sales;
}

public boolean isOutOfStock(){


return (stock<=0);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Product other = (Product) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}

public String toString(){


return name;
}

Page 2

You might also like