|
@@ -21,7 +21,9 @@ public class DatabaseMapper {
|
|
|
public T map(ResultSet rs) {
|
|
|
try {
|
|
|
T obj = (T) dbTable.entity().getConstructor().newInstance();
|
|
|
- rs.next();
|
|
|
+ if (!rs.next()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
for(Field field : dbTable.entity().getFields()) {
|
|
|
if(!field.isAnnotationPresent(DbField.class)) {
|
|
|
continue;
|
|
@@ -33,7 +35,7 @@ public class DatabaseMapper {
|
|
|
if(value != null && link != null) {
|
|
|
DatabaseUtils.checkIfPersistable(field);
|
|
|
Long otherId = (Long) value;
|
|
|
- if(otherId == 0) {
|
|
|
+ if(otherId == null || otherId == 0) {
|
|
|
value = null;
|
|
|
} else {
|
|
|
String[] split = field.getType().getName().split("\\.");
|
|
@@ -48,7 +50,7 @@ public class DatabaseMapper {
|
|
|
}
|
|
|
return obj;
|
|
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | SQLException | ClassNotFoundException e) {
|
|
|
- throw new IllegalStateException("Unable to map value to the entity");
|
|
|
+ throw new IllegalStateException("Unable to map value to the entity", e);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -74,7 +76,7 @@ public class DatabaseMapper {
|
|
|
if(value != null && link != null) {
|
|
|
DatabaseUtils.checkIfPersistable(field);
|
|
|
Long otherId = (Long) value;
|
|
|
- if(otherId == 0) {
|
|
|
+ if(otherId == null || otherId == 0) {
|
|
|
value = null;
|
|
|
} else {
|
|
|
String[] split = field.getType().getName().split("\\.");
|