Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class Customers implements Serializable {
  2.  
  3. @EmbeddedId
  4. protected CustomersPK customersPK;
  5. ...
  6. }
  7.  
  8. @Embeddable
  9. public class CustomersPK implements Serializable {
  10. @Basic(optional = false)
  11. @Column(name = "id")
  12. private int id;
  13.  
  14. @Basic(optional = false)
  15. @NotNull
  16. @Column(name = "classes_id")
  17. private int classesId;
  18. .....
  19. }
  20.  
  21. Classes cl = em.find(Classes.class, classId);
  22.  
  23. CustomersPK custPK = new CustomersPK();
  24. custPK.setClassesId(cl.getId());
  25. Customers cust = new Customers(custPK);
  26.  
  27. em.persist(cust);
  28. em.flush();
  29.  
  30.  
  31. // The problem is right here where id always equals 0
  32. int id = cust.getCustomerspk().getId();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement