e;
/**
*
*author Humanity
*/
@ Entity
@ Table (name= SHIPMENT )
@ NamedQueries ({@ NamedQuery (name= Shipment.findAll raquo ;, query= SELECT s FROM Shipment s ),NamedQuery (name= Shipment.findById raquo ;, query= SELECT s FROM Shipment s WHERE s.id =: id ),NamedQuery (name= Shipment.findByQuantity raquo ;, query= SELECT s FROM Shipment s WHERE s.quantity =: quantity ),NamedQuery (name= Shipment.findByDatetime raquo ;, query= SELECT s FROM Shipment s WHERE s.datetime =: datetime )}) class Shipment implements Serializable {static final long serialVersionUID=1L;
@ Id
@ GeneratedValue (strategy=GenerationType.IDENTITY)
@ Basic (optional=false)
@ Column (name= ID ) Integer id;
@ Basic (optional=false)
@ Column (name= QUANTITY ) int quantity;
@ Column (name= DATETIME )
@ Temporal (TemporalType.TIMESTAMP) Date datetime;
@ JoinColumn (name= RESPONSIBLEPERSONID raquo ;, referencedColumnName= ID )
@ ManyToOne (optional=false) Employee responsiblepersonid;
@ JoinColumn (name= PRODUCTID raquo ;, referencedColumnName= ID )
@ ManyToOne (optional=false) Product productid; Shipment () {
} Shipment (Integer id) {.id=id;
} Shipment (Integer id, int quantity) {.id=id; .quantity=quantity;
} Integer getId () {id;
} void setId (Integer id) {.id=id;
} int getQuantity () {quantity;
} void setQuantity (int quantity) {.quantity=quantity;
} Date getDatetime () {datetime;
} void setDatetime (Date datetime) {.datetime=datetime;
} Employee getResponsiblepersonid () {responsiblepersonid;
} void setResponsiblepersonid (Employee responsiblepersonid) {.responsiblepersonid=responsiblepersonid;
} Product getProductid () {productid;
} void setProductid (Product productid) {.productid=productid;
}
@ Overrideint hashCode () {hash=0; +=(id!=null? id.hashCode (): 0); hash;
}
@ Overrideboolean equals (Object object) {
//TODO: Warning - this method will not work in the case the id fields are not set (! (object instanceof Shipment)) {false;
} other=(Shipment) object; ((this.id == null amp; amp; other.id!=null) || (this.id!=null amp; amp;! this.id.equals (other.id))) {false;
} true;
}
@ OverrideString toString () { Entities.Shipment [id= + Id + ] raquo ;;
}
}
Шар доступу до даних
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/DAL;Entities.Employee;java.util.List;javax.persistence.EntityManager;javax.persistence.EntityTransaction;javax.persistence.Query;
/**
*
*author Humanity
*/class EmployeeRepository {EntityManager entityManager; String GetAllEmployeesQuery= select e from Employee e raquo ;; EmployeeRepository (EntityManager entityManager) {.entityManager=entityManager;
} List lt; Employee gt; GetAllEmployees () {query=entityManager.createQuery (GetAllEmployeesQuery); query.getResultList ();
} Employee GetEmployeeById (int employeeId) {employee=entityManager.find (Employee.class, employeeId); employee;
} void InsertEmployee (Employee employee) {t=entityManager.getTransaction () ;. begin (); {. persist (employee) ;. flush () ;. commit ();
} catch (Exception ex) {.rollback ();
}
} void UpdateEmployee (Employee employee) {t=entityManager.getTransaction () ;. begin (); {. refresh (employee) ;. flush () ;. commit ();
} catch (Exception ex) {.rollback ();
}
} void DeleteEmployee (int employeeId) {t=entityManager.getTransaction () ;. begin (); {Employee=GetEmployeeById (employeeId) ;. remove (Employee) ;. flush () ;. commit ();
} catch (Exception ex) {.rollback ();
<...