{"record":{"id":"d291c0086a76aa34","repo":"quarkusio/quarkus","slug":"currently-the-version-annotation-can-only-be-plac","errorCode":null,"errorMessage":"Currently the @Version annotation can only be placed on a single field or method. Offending class is ${entity}","messagePattern":"Currently the @Version annotation can only be placed on a single field or method\\. Offending class is (.+?)","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":1259,"sourceCode":"    }\n\n    private Optional<AnnotationTarget> getVersionAnnotationTargetRec(DotName currentDotName, IndexView index,\n            DotName originalEntityDotName) {\n        ClassInfo classInfo = index.getClassByName(currentDotName);\n        if (classInfo == null) {\n            throw new IllegalStateException(\"Entity \" + originalEntityDotName + \" was not part of the Quarkus index\");\n        }\n\n        if (!classInfo.annotationsMap().containsKey(DotNames.VERSION)) {\n            if (DotNames.OBJECT.equals(classInfo.superName())) {\n                return Optional.empty();\n            }\n            return getVersionAnnotationTargetRec(classInfo.superName(), index, originalEntityDotName);\n        }\n\n        List<AnnotationInstance> annotationInstances = classInfo.annotationsMap().get(DotNames.VERSION);\n        if (annotationInstances.size() > 1) {\n            throw new IllegalArgumentException(\n                    \"Currently the @Version annotation can only be placed on a single field or method. \" +\n                            \"Offending class is \" + originalEntityDotName);\n        }\n\n        return Optional.of(annotationInstances.get(0).target());\n    }\n}\n","sourceCodeStart":1241,"sourceCodeEnd":1267,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/StockMethodsAdder.java#L1241-L1267","documentation":"The extension supports at most one @Version annotation per entity hierarchy when generating optimistic-locking-aware save methods. If more than one @Version target is found on the entity or its superclasses, the build fails with this IllegalArgumentException because it cannot decide which version attribute to use.","triggerScenarios":"Two fields annotated @Version within one hierarchy — e.g., a version field in the entity and another in a superclass, or @Version on both a field and its getter.","commonSituations":"Refactoring where a base entity already had @Version and a subclass added its own; copy-paste between entities; multiple inheritance levels each adding version columns.","solutions":["Keep exactly one @Version field in the whole hierarchy; remove the rest","Prefer the @Version in the abstract base entity and delete subclass duplicates","Ensure @Version is on either the field or the getter, never both","Use supported @Version types (int, Integer, long, Long, short, Short, java.sql.Timestamp, etc.)"],"exampleFix":"// before\nclass BaseEntity { @Version private long v1; }\n@Entity class User extends BaseEntity { @Version private long v2; }\n\n// after\nclass BaseEntity { @Version private long v1; }\n@Entity class User extends BaseEntity { /* no second @Version */ }","handlingStrategy":"validation","validationCode":"// Ensure single @Version in hierarchy:\nlong v = java.util.Arrays.stream(User.class.getDeclaredFields())\n    .filter(f -> f.isAnnotationPresent(jakarta.persistence.Version.class)).count();\nif (v > 1) throw new IllegalStateException(\"Multiple @Version fields in hierarchy\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare @Version only once, ideally in a shared base entity","Add an ArchUnit rule banning multiple @Version fields","Never annotate both field and getter with @Version","Review superclass entities when adding version columns"],"tags":["quarkus","spring-data-jpa","jpa","optimistic-locking","build-time"],"backgroundTag":"duplicate-jpa-version-annotation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}