Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. @Entity
  2. @Table(name = "ticket")
  3. @XmlRootElement
  4. public class Ticket implements Serializable {
  5. private static final long serialVersionUID = 1L;
  6. @Id
  7. @GeneratedValue(strategy = GenerationType.IDENTITY)
  8. @Basic(optional = false)
  9. @Column(name = "ticket_id")
  10. private Long ticketId;
  11. @Column(name = "description")
  12. private String description;
  13. @Column(name = "note")
  14. private String note;
  15. @ManyToOne(targetEntity=LoginInfo.class,cascade=CascadeType.ALL)
  16. private LoginInfo createdBy;
  17.  
  18. @Entity
  19. @Table(name = "login_info")
  20. @XmlRootElement
  21. public class LoginInfo implements Serializable {
  22. private static final long serialVersionUID = 1L;
  23. @Id
  24. @GeneratedValue(strategy = GenerationType.IDENTITY)
  25. @Basic(optional = false)
  26. @Column(name = "login_info_id")
  27. private Long loginInfoId;
  28. @Column(name = "username")
  29. private String username;
  30. @Column(name = "pwd")
  31. private String pwd;
  32. @Column(name = "role")
  33. private String role = "user";
  34. @OneToMany(cascade=CascadeType.ALL, mappedBy="loginInfo1")
  35. private List<UserInfo> userInfoList;
  36. @OneToMany(cascade=CascadeType.MERGE, mappedBy="createdBy")
  37. private List<Ticket> createdByList;
  38.  
  39. public Ticket create(Ticket t) {
  40.  
  41. Ticket ticket = new Ticket();
  42. try{
  43. //LoginInfo login = findUser(t.getCreatedBy().getUsername());
  44. tx.begin();
  45. ticket.setDescription(t.getDescription());
  46. ticket.setNote(t.getNote());
  47. ticket.setDateCreated(new Date());
  48. ticket.setCreatedBy(t.getCreatedBy());
  49. em.persist(ticket);
  50. tx.commit();
  51. }catch(Exception e){
  52. e.toString();
  53. }
  54.  
  55. return ticket;
  56. }
  57.  
  58. Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
  59. Column 'pwd' cannot be null
  60. Error Code: 1048
  61. Call: INSERT INTO login_info (pwd, role, username) VALUES (?, ?, ?)
  62. bind => [3 parameters bound]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement