Ejemplo n.º 1
0
  public void testMappedQueryObjectWithNullForPrimitiveIntField() throws Exception {
    h.insert("insert into something (id, name, intValue) values (1, 'eric', null)");

    Query<Something> query =
        h.createQuery("select * from something order by id").map(Something.class);

    List<Something> r = query.list();
    Something eric = r.get(0);
    assertEquals("eric", eric.getName());
    assertEquals(1, eric.getId());
    assertEquals(0, eric.getIntValue());
  }
Ejemplo n.º 2
0
  public void testMappedQueryObject() throws Exception {
    h.insert("insert into something (id, name) values (1, 'eric')");
    h.insert("insert into something (id, name) values (2, 'brian')");

    Query<Something> query =
        h.createQuery("select * from something order by id").map(Something.class);

    List<Something> r = query.list();
    Something eric = r.get(0);
    assertEquals("eric", eric.getName());
    assertEquals(1, eric.getId());
  }
Ejemplo n.º 3
0
  public void testMapper() throws Exception {
    h.insert("insert into something (id, name) values (1, 'eric')");
    h.insert("insert into something (id, name) values (2, 'brian')");

    Query<String> query =
        h.createQuery("select name from something order by id")
            .map(
                new ResultSetMapper<String>() {
                  public String map(int index, ResultSet r, StatementContext ctx)
                      throws SQLException {
                    return r.getString(1);
                  }
                });

    String name = query.list().get(0);
    assertEquals("eric", name);
  }