Guest User

Untitled

a guest
Nov 2nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public class HiberhateUtil {
  2.  
  3. private static SessionFactory sessionFactory = null;
  4.  
  5. public static SessionFactory getSesssionFactory() {
  6. try{
  7. // A SessionFactory is set up once for an application
  8. sessionFactory = new Configuration()
  9. .configure("/hibenate.cfg.xml") // configures settings from hibernate.cfg.xml
  10. .buildSessionFactory();
  11. }
  12. catch(Throwable ex){
  13. System.err.println("Session Factory creation failed: " + ex);
  14. throw new ExceptionInInitializerError(ex);
  15. }
  16. return sessionFactory;
  17. }
  18. }
  19.  
  20. @Entity
  21. @Table(name = "users")
  22. public class User {
  23.  
  24. public static final String SELECT_USER_COUNT_BY_LOGIN = "select_user_count_by_login";
  25.  
  26. @Id
  27. @GeneratedValue(strategy = GenerationType.IDENTITY)
  28. private int id;
  29. @Column(name = "date", columnDefinition = "Integer", nullable = false)
  30. private int date;
  31. @Column(name = "name", columnDefinition = "varchar(255)", nullable = false)
  32. private String name;
  33. @Column(name = "userName", columnDefinition = "varchar(256)", nullable = false)
  34. private String userName;
  35. @Column(name = "password", columnDefinition = "varchar(256)", nullable = false)
  36. private String password;
  37. @Column(name = "country", columnDefinition = "varchar(256)", nullable = false)
  38. private String country;
  39. @Column(name = "phone", columnDefinition = "varchar(256)", nullable = false)
  40. private String phone;
  41. @Column(name = "email", columnDefinition = "varchar(256)", nullable = false, unique = true)
  42. private String email;
  43.  
  44. <hibernate-configuration>
  45. <session-factory>
  46. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  47. <property name="hibernate.connection.password">root</property>
  48. <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/personal</property>
  49. <property name="hibernate.connection.username">postgres</property>
  50. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  51. <property name="hibernate.current_session_context_class">thread</property>
  52.  
  53. <mapping class="users.User"></mapping>
  54. </session-factory>
  55. </hibernate-configuration>
Add Comment
Please, Sign In to add comment