[#1768] NullPointerException when DAO.fetchOne() returns no record

This commit is contained in:
Lukas Eder 2012-08-30 18:39:19 +02:00
parent 69a23ecb0d
commit 490478cd38
2 changed files with 9 additions and 4 deletions

View File

@ -94,6 +94,10 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals(2, TAuthorDao().count());
assertEquals(2, TAuthorDao().findAll().size());
// [#1768] Unknown records should return null
assertNull(TAuthorDao().findById(3));
assertNull(TAuthorDao().fetchOne(TAuthor_ID(), 3));
AP id1 = TAuthorDao().findById(1);
assertEquals(1, on(id1).get("id"));
assertEquals("George", on(id1).get("firstName"));

View File

@ -222,10 +222,11 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
@Override
public final <Z> P fetchOne(Field<Z> field, Z value) {
return create.selectFrom(table)
.where(field.equal(value))
.fetchOne()
.into(type);
R record = create.selectFrom(table)
.where(field.equal(value))
.fetchOne();
return record == null ? null : record.into(type);
}
@Override