Guest User

Untitled

a guest
Nov 2nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public class UsersDAO {
  2.  
  3. @Autowired
  4. SessionFactory factory;
  5.  
  6. public int add(User user) {
  7. Session session = factory.openSession();
  8. Serializable id = session.save(user);
  9. session.close();
  10. return (Integer) id;
  11. }
  12. }
  13.  
  14. @Entity
  15. @Table(name = "users")
  16. @NamedQuery(name = User.SELECT_USER_COUNT_BY_LOGIN, query = "select count(id) from User where email=:login")
  17. public class User {
  18.  
  19. public static final String SELECT_USER_COUNT_BY_LOGIN = "select_user_count_by_login";
  20.  
  21. @Id
  22. @GeneratedValue(strategy = GenerationType.IDENTITY)
  23. private int id;
  24. @Column(name = "date", columnDefinition = "Integer", nullable = false)
  25. private int date;
  26. @Column(name = "name", columnDefinition = "varchar(255)", nullable = false)
  27. private String name;
  28. @Column(name = "userName", columnDefinition = "varchar(256)", nullable = false)
  29. private String userName;
  30. @Column(name = "password", columnDefinition = "varchar(256)", nullable = false)
  31. private String password;
  32. @Column(name = "country", columnDefinition = "varchar(256)", nullable = false)
  33. private String country;
  34. @Column(name = "phone", columnDefinition = "varchar(256)", nullable = false)
  35. private String phone;
  36. @Column(name = "email", columnDefinition = "varchar(256)", nullable = false, unique = true)
  37. private String email;
  38.  
  39. public User() {}
  40.  
  41. db.driver=org.postgresql.Driver
  42. db.url=jdbc:postgresql://localhost:5432/personal
  43. db.username=postgres
  44. db.password=root
  45.  
  46. hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
  47. hibernate.show_sql=true
  48. hibernate.hbm2ddl.auto=update
Add Comment
Please, Sign In to add comment