From 42f08af60989999534f955fae3144305418a5aed Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Sun, 11 Sep 2022 19:27:14 -0300 Subject: [PATCH 1/3] Fixed error when inserting a row in the database with a primary key of type long from a table generated by `database.createTable(Class.class)` --- .../com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java index cc84e75..fd2af8c 100644 --- a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java +++ b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java @@ -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; @@ -297,6 +298,9 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.writeMethod != null) { try { + if (value instanceof BigInteger) { + 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: " @@ -308,6 +312,9 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.field != null) { try { + if (value instanceof BigInteger) { + value = ((BigInteger) value).longValue(); + } prop.field.set(pojo, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new DbException( From e45d85c58a963f6d75b14273f6cc218e0a1d363a Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Sun, 11 Sep 2022 21:46:25 -0300 Subject: [PATCH 2/3] added validation if the field with `@Id` is of type `long` --- .../com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java index fd2af8c..3b13a27 100644 --- a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java +++ b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java @@ -298,8 +298,10 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.writeMethod != null) { try { - if (value instanceof BigInteger) { - value = ((BigInteger) value).longValue(); + if (value instanceof BigInteger && prop.writeMethod.getParameterCount() >= 1) { + if (prop.writeMethod.getParameterTypes()[0].equals(Long.TYPE)) { + value = ((BigInteger) value).longValue(); + } } prop.writeMethod.invoke(pojo, value); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { @@ -312,7 +314,7 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.field != null) { try { - if (value instanceof BigInteger) { + if (value instanceof BigInteger && prop.field.getType().equals(Long.TYPE)) { value = ((BigInteger) value).longValue(); } prop.field.set(pojo, value); From edb0e9bdc5b3c70da15803fa1248cf886cf938f0 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Mon, 12 Sep 2022 09:57:52 -0300 Subject: [PATCH 3/3] added validation if the field with `@Id` is of type `Long` --- .../com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java index 3b13a27..26b2875 100644 --- a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java +++ b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardPojoInfo.java @@ -299,7 +299,8 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.writeMethod != null) { try { if (value instanceof BigInteger && prop.writeMethod.getParameterCount() >= 1) { - if (prop.writeMethod.getParameterTypes()[0].equals(Long.TYPE)) { + Class type = prop.writeMethod.getParameterTypes()[0]; + if (type.equals(Long.TYPE) || type.equals(Long.class)) { value = ((BigInteger) value).longValue(); } } @@ -314,8 +315,10 @@ public void putValue(Object pojo, String name, Object value, boolean ignoreIfMis if (prop.field != null) { try { - if (value instanceof BigInteger && prop.field.getType().equals(Long.TYPE)) { - value = ((BigInteger) value).longValue(); + 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) {