Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error when inserting a row in the database with a primary key o… #79

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -297,6 +298,12 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis

if (prop.writeMethod != null) {
try {
if (value instanceof BigInteger && prop.writeMethod.getParameterCount() >= 1) {
Class type = prop.writeMethod.getParameterTypes()[0];
if (type.equals(Long.TYPE) || type.equals(Long.class)) {
value = ((BigInteger) value).longValue();
}
}
prop.writeMethod.invoke(pojo, value);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new DbException("Could not write value into pojo. Property: " + prop.name + " method: "
Expand All @@ -308,6 +315,11 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis

if (prop.field != null) {
try {
if (value instanceof BigInteger) {
if (prop.field.getType().equals(Long.TYPE) || prop.field.getType().equals(Long.class)) {
value = ((BigInteger) value).longValue();
}
}
prop.field.set(pojo, value);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new DbException(
Expand Down