• Post Reply Bookmark Topic Watch Topic
  • New Topic

Update of table with a Composite key

 
Guy Belpa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i doing a project using EJB and mysql..
i need to do a table update of a table which have composite key..

@Entity
@Table(name = "order_details")
@NamedQueries({@NamedQuery(name = "OrderDetails.findByOrderId", query = "SELECT o FROM OrderDetails o WHERE o.orderDetailsPK.orderId = rderId"), @NamedQuery(name = "OrderDetails.findByItemId", query = "SELECT o FROM OrderDetails o WHERE o.orderDetailsPK.itemId = :itemId"), ...........

public class OrderDetails implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected OrderDetailsPK orderDetailsPK;
..........
.............


This is the method i wrote to UPDATE my table...

public boolean updatePurchaseOrder(PurchaseOrderDAO purchaseOrderDAO) {

Query q = em.createNamedQuery("OrderDetails.findByOrderId");

//q.setParameter("orderId",purchaseOrderDAO.getSupplier_id());
q.setParameter("orderId","0011");
q = em.createNamedQuery("OrderDetails.findByItemId");
q.setParameter("itemId","SELI");
OrderDetails s = (OrderDetails) q.getSingleResult();

s.setSupplierId(purchaseOrderDAO.getSupplier_id());
s.setPoNum(purchaseOrderDAO.getPo_num());
s.setPoDate(purchaseOrderDAO.getPo_date());
s.setUom(purchaseOrderDAO.getUom());
s.setUPrice(purchaseOrderDAO.getU_price());
s.setDelTerms(purchaseOrderDAO.getDel_terms());
s.setRemarks(purchaseOrderDAO.getRemarks());
s.setDelPerson(purchaseOrderDAO.getDel_person());
s.setDelpernum(purchaseOrderDAO.getDelpernum());
s.setDelperdvn(purchaseOrderDAO.getDelperdvn());
s.setDelperadrs(purchaseOrderDAO.getDelperadrs());
s.setDelperadrs(purchaseOrderDAO.getBckup1());
s.setDelperadrs(purchaseOrderDAO.getBckup2());
s.setDelperadrs(purchaseOrderDAO.getBckup3());
em.merge(s);
return true;
}


i feel like some wrong with this method...
Can smone help me on this...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!