Search in sources :

Example 1 with Car

use of ru.ivmiit.models.Car 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)

Aggregations

Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1 Car (ru.ivmiit.models.Car)1 User (ru.ivmiit.models.User)1