{"record":{"id":"c038a253b9ce92bd","repo":"hibernate/hibernate-orm","slug":"attributeaccessor-annotation-must-specify-a-st","errorCode":null,"errorMessage":"'@AttributeAccessor' annotation must specify a 'strategy'","messagePattern":"'@AttributeAccessor' annotation must specify a 'strategy'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/binder/internal/AttributeAccessorBinder.java","lineNumber":32,"sourceCode":"\n/**\n * Configures the {@link PropertyAccessStrategy} for an attribute.\n *\n * @author Gavin King\n */\npublic class AttributeAccessorBinder implements AttributeBinder<AttributeAccessor> {\n\t@Override\n\tpublic void bind(\n\t\t\tAttributeAccessor accessor,\n\t\t\tMetadataBuildingContext buildingContext,\n\t\t\tPersistentClass persistentClass,\n\t\t\tProperty property) {\n\t\tfinal var type = accessor.strategy();\n\t\tif ( !PropertyAccessStrategy.class.equals(type) ) {\n\t\t\tproperty.setPropertyAccessorName( type.getName() );\n\t\t}\n\t\telse {\n\t\t\tthrow new AnnotationException(\"'@AttributeAccessor' annotation must specify a 'strategy'\");\n\t\t}\n\t}\n}\n","sourceCodeStart":14,"sourceCodeEnd":36,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/binder/internal/AttributeAccessorBinder.java#L14-L36","documentation":"@AttributeAccessor's strategy attribute defaults to the PropertyAccessStrategy interface itself, which acts as the 'not specified' marker. AttributeAccessorBinder treats that default as a mapping error - an accessor annotation without a strategy would silently change nothing - and throws AnnotationException at bootstrap.","triggerScenarios":"Writing @AttributeAccessor with no attributes (or explicitly strategy = PropertyAccessStrategy.class) on an entity field/property/class during annotation binding.","commonSituations":"IDE auto-completion inserting the marker interface; copy-pasting the annotation without the strategy attribute; intending a custom accessor but forgetting the attribute.","solutions":["Specify a concrete strategy: @AttributeAccessor(strategy = MyPropertyAccessStrategy.class).","If no custom accessor is wanted, delete the annotation."],"exampleFix":"// before\n@AttributeAccessor // or strategy = PropertyAccessStrategy.class\nprivate String name;\n// after\n@AttributeAccessor(strategy = MyPropertyAccessStrategy.class)\nprivate String name;","handlingStrategy":"validation","validationCode":"// scan entities at startup so the bad annotation surfaces before runtime\nfor (Class<?> c : entityClasses) {\n    for (Field f : c.getDeclaredFields()) {\n        AttributeAccessor a = f.getAnnotation(AttributeAccessor.class);\n        if (a != null && PropertyAccessStrategy.class.equals(a.strategy())) {\n            throw new IllegalStateException(c.getName() + \".\" + f.getName() + \" has @AttributeAccessor without a strategy\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always specify strategy = YourPropertyAccessStrategy.class on @AttributeAccessor","Delete the annotation when no custom access strategy is needed"],"tags":["hibernate","mapping","annotation","property-access"],"backgroundTag":"missing-annotation-attribute","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}