{"record":{"id":"2e7540eb5c903724","repo":"hibernate/hibernate-orm","slug":"unsupported-identifier-type","errorCode":null,"errorMessage":"Unsupported identifier type: ","messagePattern":"Unsupported identifier type: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/spi/JsonGeneratingVisitor.java","lineNumber":304,"sourceCode":"\tprotected void serializeEntityIdentifier(\n\t\t\tObject value,\n\t\t\tEntityIdentifierMapping identifierMapping,\n\t\t\tWrapperOptions options,\n\t\t\tJsonDocumentWriter writer) throws IOException {\n\t\tfinal Object identifier = identifierMapping.getIdentifier( value );\n\t\tif ( identifierMapping instanceof SingleAttributeIdentifierMapping singleAttribute ) {\n\t\t\twriter.serializeJsonValue(\n\t\t\t\t\tidentifier,\n\t\t\t\t\tsingleAttribute.getJavaType(),\n\t\t\t\t\tsingleAttribute.getSingleJdbcMapping().getJdbcType(),\n\t\t\t\t\toptions\n\t\t\t);\n\t\t}\n\t\telse if ( identifier instanceof CompositeIdentifierMapping composite ) {\n\t\t\tvisit( composite.getMappedType(), identifier, options, writer );\n\t\t}\n\t\telse {\n\t\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\t\"Unsupported identifier type: \" + identifier.getClass().getName() );\n\t\t}\n\t}\n}\n","sourceCodeStart":286,"sourceCodeEnd":309,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/spi/JsonGeneratingVisitor.java#L286-L309","documentation":"Inside a JSON aggregate Hibernate serializes referenced entities as just their identifier (serializeEntity -> serializeEntityIdentifier). It can write identifiers whose EntityIdentifierMapping is a SingleAttributeIdentifierMapping (simple @Id and single-attribute @EmbeddedId). The fallback branch only accepts an identifier VALUE that is itself a CompositeIdentifierMapping - which effectively never happens, since getIdentifier(value) returns the user's id object, not a mapping - so any other identifier shape throws UnsupportedOperationException naming the identifier's class.","triggerScenarios":"A to-one reference (or element mapping) inside a JSON aggregate pointing at an entity whose primary key uses @IdClass (non-aggregated composite id): identifierMapping is not single-attribute and getIdentifier(value) returns the IdClass instance, so the else branch fires. Custom EntityIdentifierMapping implementations hit it too.","commonSituations":"Legacy schemas with @IdClass entities pulled into newer JSON aggregate mappings; embedding references to composite-key entities inside jsonb/OSON columns; migrating models to JSON storage while keeping @IdClass.","solutions":["Switch the referenced entity to @EmbeddedId (single-attribute composite id) or a simple @Id","Do not reference the entity from the JSON aggregate - store basic FK value(s) (one column per id field) inside the embeddable instead","Upgrade Hibernate ORM - identifier serialization for aggregates keeps being extended; report the case if it persists"],"exampleFix":"// before\nclass OrderUserId implements Serializable { Long tenantId; Long seq; } // @IdClass\n@Entity @IdClass(OrderUserId.class)\nclass OrderUser { @Id Long tenantId; @Id Long seq; }\n\n// after\n@Entity\nclass OrderUser {\n    @EmbeddedId\n    private OrderUserId id; // single-attribute composite id serializes inside JSON aggregates\n}","handlingStrategy":"validation","validationCode":"// Verify every entity referenced from JSON aggregates has a single-attribute id\nfor (EntityBinding b : referencedEntities) {\n    if (b.idUsesIdClass()) { // detected via @IdClass on the entity class\n        throw new IllegalStateException(\"Entity \" + b.name + \" with @IdClass cannot be referenced from a JSON aggregate\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer @EmbeddedId or simple @Id over @IdClass when entities may be referenced from aggregates","Store basic FK values inside aggregates instead of entity references","Re-test aggregate serialization after changing identifier strategies"],"tags":["hibernate","json","composite-id","idclass","aggregate-mapping"],"backgroundTag":"composite-id-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}