Пример #1
0
  @Test
  public void testInsertUsingHibernate() {

    Session session = HibernateUtil.getSessionFactory().openSession();

    session.beginTransaction();

    DBUser dbUser = new DBUser();
    dbUser.setUsername("ColinB");
    dbUser.setCreatedBy("Colin But");

    session.save(dbUser);

    session.getTransaction().commit();

    HibernateUtil.shutdown();
  }
Пример #2
0
  @Test
  public void testRetreivingUsingHibernate() {

    Session session = HibernateUtil.getSessionFactory().openSession();

    session.beginTransaction();

    Query query = session.createQuery("from DBUser");

    @SuppressWarnings("unchecked")
    List<DBUser> dbUsers = query.list();
    for (DBUser dbUser : dbUsers) {
      System.out.println(dbUser);
    }

    session.getTransaction().commit();

    HibernateUtil.shutdown();
  }