Esempio n. 1
0
  /**
   * Test method.
   *
   * @throws Exception For any exception thrown.
   */
  public void testLoadChild() throws Exception {
    Database db = _category.getDatabase();
    db.begin();

    Child child = (Child) db.load(Child.class, new Integer(1));

    assertNotNull(child);
    assertEquals(new Integer(1), child.getId());

    db.commit();
    db.close();
  }
Esempio n. 2
0
  @Test
  public void testOrderedList() throws Exception {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    Child luke = new Child();
    luke.setName("Luke");
    Child leia = new Child();
    leia.setName("Leia");
    session.persist(luke);
    session.persist(leia);
    Father father = new Father();
    father.getOrderedChildren().add(luke);
    father.getOrderedChildren().add(null);
    father.getOrderedChildren().add(leia);
    session.persist(father);
    tx.commit();

    session.clear();

    tx = session.beginTransaction();
    father = (Father) session.get(Father.class, father.getId());
    assertThat(father.getOrderedChildren()).as("List should have 3 elements").hasSize(3);
    assertThat(father.getOrderedChildren().get(0).getName())
        .as("Luke should be first")
        .isEqualTo(luke.getName());
    assertThat(father.getOrderedChildren().get(1)).as("Second born should be null").isNull();
    assertThat(father.getOrderedChildren().get(2).getName())
        .as("Leia should be third")
        .isEqualTo(leia.getName());
    session.delete(father);
    session.delete(session.load(Child.class, luke.getId()));
    session.delete(session.load(Child.class, leia.getId()));
    tx.commit();

    session.close();

    checkCleanCache();
  }