Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HiberhateUtil {
- private static SessionFactory sessionFactory = null;
- public static SessionFactory getSesssionFactory() {
- try{
- // A SessionFactory is set up once for an application
- sessionFactory = new Configuration()
- .configure("/hibenate.cfg.xml") // configures settings from hibernate.cfg.xml
- .buildSessionFactory();
- }
- catch(Throwable ex){
- System.err.println("Session Factory creation failed: " + ex);
- throw new ExceptionInInitializerError(ex);
- }
- return sessionFactory;
- }
- }
- @Entity
- @Table(name = "users")
- public class User {
- public static final String SELECT_USER_COUNT_BY_LOGIN = "select_user_count_by_login";
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- @Column(name = "date", columnDefinition = "Integer", nullable = false)
- private int date;
- @Column(name = "name", columnDefinition = "varchar(255)", nullable = false)
- private String name;
- @Column(name = "userName", columnDefinition = "varchar(256)", nullable = false)
- private String userName;
- @Column(name = "password", columnDefinition = "varchar(256)", nullable = false)
- private String password;
- @Column(name = "country", columnDefinition = "varchar(256)", nullable = false)
- private String country;
- @Column(name = "phone", columnDefinition = "varchar(256)", nullable = false)
- private String phone;
- @Column(name = "email", columnDefinition = "varchar(256)", nullable = false, unique = true)
- private String email;
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.password">root</property>
- <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/personal</property>
- <property name="hibernate.connection.username">postgres</property>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.current_session_context_class">thread</property>
- <mapping class="users.User"></mapping>
- </session-factory>
- </hibernate-configuration>
Add Comment
Please, Sign In to add comment