[#1768] NullPointerException when DAO.fetchOne() returns no record
This commit is contained in:
parent
69a23ecb0d
commit
490478cd38
@ -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"));
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user