{"record":{"id":"8b6c2f895d4b41f6","repo":"quarkusio/quarkus","slug":"id-type-of-entity-is-invalid","errorCode":null,"errorMessage":"Id type of '${entity}' is invalid.","messagePattern":"Id type of '(.+?)' is invalid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/StockMethodsAdder.java","lineNumber":193,"sourceCode":"                                if (versionType instanceof PrimitiveType) {\n                                    throw new IllegalArgumentException(\n                                            \"The '@Version' annotation cannot be used on primitive types. Offending entity is '\"\n                                                    + entityDotName + \"'.\");\n                                }\n                                Expr versionValue = generateObtainValue(bc, entityDotName, entityParam,\n                                        versionValueTarget.get());\n                                bc.ifElse(bc.isNull(versionValue),\n                                        tb -> generatePersistAndReturn(entityParam, tb, opsVar),\n                                        fb -> generateMergeAndReturn(entityParam, fb, opsVar,\n                                                entityClassVar));\n                                // if version is present, we've handled both branches, so return here\n                                return;\n                            }\n\n                            if (idType instanceof PrimitiveType) {\n                                if (!idType.name().equals(DotNames.PRIMITIVE_LONG)\n                                        && !idType.name().equals(DotNames.PRIMITIVE_INTEGER)) {\n                                    throw new IllegalArgumentException(\n                                            \"Id type of '\" + entityDotName + \"' is invalid.\");\n                                }\n                                Expr idValueForComparison = idValue;\n                                if (idType.name().equals(DotNames.PRIMITIVE_LONG)) {\n                                    Expr longObject = bc.invokeStatic(\n                                            MethodDesc.of(Long.class, \"valueOf\", Long.class, long.class), idValue);\n                                    idValueForComparison = bc.invokeVirtual(\n                                            MethodDesc.of(Long.class, \"intValue\", int.class), longObject);\n                                }\n                                // ifNonZero equivalent: if id != 0 => idValueSet, if id == 0 => idValueUnset\n                                bc.ifElse(bc.ne(idValueForComparison, 0),\n                                        idValueSetBlock -> generateMergeAndReturn(entityParam, idValueSetBlock,\n                                                opsVar, entityClassVar),\n                                        idValueUnsetBlock -> generatePersistAndReturn(entityParam,\n                                                idValueUnsetBlock, opsVar));\n                            } else {\n                                bc.ifElse(bc.isNull(idValue),\n                                        idValueUnsetBlock -> generatePersistAndReturn(entityParam,","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/StockMethodsAdder.java#L175-L211","documentation":"Quarkus generates save() by comparing the ID field to determine whether to persist or merge. Only primitive long and primitive int ID types are supported for this comparison; any other primitive ID type (short, byte, char, etc.) cannot be reliably null-checked/compared and augmentation fails with this error.","triggerScenarios":"An entity's @Id field is a primitive type other than long or int (e.g. short, char, byte); generating save()/saveAndFlush() for a repository of that entity hits the guard.","commonSituations":"Using unconventional primitive ID types; porting entities with compact numeric IDs; typos in ID field declarations.","solutions":["Change the @Id field to a supported type: primitive long or int, or preferably wrapper Long/Integer","Wrapper types (Long/Integer) are safest since nullability drives persist-vs-merge","Update getters/setters and any client code referencing the old ID type"],"exampleFix":"// before\n@Id\nprivate short id;\n// after\n@Id\nprivate Long id;","handlingStrategy":"validation","validationCode":"// Verify @Id field type before wiring a repository\nField id = MyEntity.class.getDeclaredField(\"id\");\nClass<?> t = id.getType();\nif (!(t == Long.class || t == Integer.class || t == long.class || t == int.class))\n    throw new IllegalStateException(\"Unsupported @Id type: \" + t);","typeGuard":"boolean hasSupportedIdType(Field f) {\n    Class<?> t = f.getType();\n    return t == Long.class || t == Integer.class || t == long.class || t == int.class;\n}","tryCatchPattern":null,"preventionTips":["Use Long or Integer for @Id fields","Avoid short/byte/char/float/double primitive IDs","Standardize entity ID types across the project"],"tags":["quarkus","spring-data-jpa","jpa","id-type","build-time"],"backgroundTag":"invalid-entity-field-type","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}