Search in sources :

Example 1 with User

use of ru.ivmiit.models.User in project JAVA_FIX by MarselSidikov.

the class Application method main.

public static void main(String[] args) {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://localhost:5432/postgres");
    configuration.setProperty("hibernate.connection.username", "postgres");
    configuration.setProperty("hibernate.connection.password", "qwerty007");
    configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL95Dialect");
    configuration.setProperty("hibernate.hbm2ddl.auto", "update");
    configuration.addResource("User.hbm.xml");
    configuration.addAnnotatedClass(Car.class);
    configuration.setProperty("hibernate.show_sql", "true");
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    Session session = sessionFactory.openSession();
    User user = session.createQuery("from User user where user.id = 1", User.class).getSingleResult();
    session.beginTransaction();
    session.save(new User("Mini", "Max", 99));
    session.getTransaction().commit();
    System.out.println(user);
    List<Car> car = session.createQuery("from Car car", Car.class).getResultList();
    int i = 0;
}
Also used : SessionFactory(org.hibernate.SessionFactory) User(ru.ivmiit.models.User) Configuration(org.hibernate.cfg.Configuration) Car(ru.ivmiit.models.Car) Session(org.hibernate.Session)

Example 2 with User

use of ru.ivmiit.models.User in project JAVA_FIX by MarselSidikov.

the class SignUpServlet method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // вытащили данные регистрации
    String name = req.getParameter("name");
    String password = req.getParameter("password");
    LocalDate birthDate = LocalDate.parse(req.getParameter("birthDate"));
    // создали пользователя и сохранили его в хранилище
    User user = new User(name, password, birthDate);
    usersRepository.save(user);
    doGet(req, resp);
}
Also used : User(ru.ivmiit.models.User) LocalDate(java.time.LocalDate)

Example 3 with User

use of ru.ivmiit.models.User in project JAVA_FIX by MarselSidikov.

the class SignUpServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    List<User> users = usersRepository.findAll();
    req.setAttribute("usersFromServer", users);
    RequestDispatcher dispatcher = req.getServletContext().getRequestDispatcher("/jsp/signUp.jsp");
    dispatcher.forward(req, resp);
}
Also used : User(ru.ivmiit.models.User) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

User (ru.ivmiit.models.User)3 LocalDate (java.time.LocalDate)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1 Car (ru.ivmiit.models.Car)1