From aa840aaa53907744c425f5f2799c3cc1e614be2c Mon Sep 17 00:00:00 2001 From: Simon/Jinyu Liu Date: Thu, 6 Aug 2020 13:32:31 -0700 Subject: [PATCH] fix the data type issue when primary key is a custom type fix for issue https://github.com/greenrobot/greenDAO/issues/1051 When primary key is a custom type, the generated code for updateKeyAfterInsert and getKey will return String but the actual primary key is not. --- DaoGenerator/src-template/dao.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DaoGenerator/src-template/dao.ftl b/DaoGenerator/src-template/dao.ftl index 08eb4eee4..3a8d0dac2 100644 --- a/DaoGenerator/src-template/dao.ftl +++ b/DaoGenerator/src-template/dao.ftl @@ -245,7 +245,7 @@ as property>\"${property.dbName}\"<#if (index.propertiesOrder[property_index])?? return rowId; <#else> - return entity.get${entity.pkProperty.propertyName?cap_first}(); + return (${entity.pkType}) entity.get${entity.pkProperty.propertyName?cap_first}(); <#else> // Unsupported or missing PK type @@ -257,7 +257,7 @@ as property>\"${property.dbName}\"<#if (index.propertiesOrder[property_index])?? public ${entity.pkType} getKey(${entity.className} entity) { <#if entity.pkProperty??> if(entity != null) { - return entity.get${entity.pkProperty.propertyName?cap_first}(); + return (${entity.pkType}) entity.get${entity.pkProperty.propertyName?cap_first}(); } else { return null; }