{"record":{"id":"b36c0933328ee621","repo":"hibernate/hibernate-orm","slug":"unsupported-attempt-to-unwrap-map-entry-value","errorCode":null,"errorMessage":"Unsupported attempt to unwrap Map.Entry value","messagePattern":"Unsupported attempt to unwrap Map\\.Entry value","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaType.java","lineNumber":36,"sourceCode":" */\npublic class MapEntryJavaType extends AbstractClassJavaType<Map.Entry> {\n\t/**\n\t * Singleton access\n\t */\n\tpublic static final MapEntryJavaType INSTANCE = new MapEntryJavaType();\n\n\tpublic MapEntryJavaType() {\n\t\tsuper( Map.Entry.class );\n\t}\n\n\t@Override\n\tpublic JdbcType getRecommendedJdbcType(JdbcTypeIndicators context) {\n\t\tthrow new UnsupportedOperationException( \"Unsupported attempt to resolve JDBC type for Map.Entry\" );\n\t}\n\n\t@Override\n\tpublic <X> X unwrap(Map.Entry value, Class<X> type, WrapperOptions options) {\n\t\tthrow new UnsupportedOperationException( \"Unsupported attempt to unwrap Map.Entry value\" );\n\t}\n\n\t@Override\n\tpublic <X> Map.Entry wrap(X value, WrapperOptions options) {\n\t\tthrow new UnsupportedOperationException( \"Unsupported attempt to wrap Map.Entry value\" );\n\t}\n}\n","sourceCodeStart":18,"sourceCodeEnd":44,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaType.java#L18-L44","documentation":"Even when a Map.Entry value exists at runtime, Hibernate cannot convert it to any JDBC type: unwrap() on MapEntryJavaType throws UnsupportedOperationException. Map.Entry is a query-time projection (HQL entry(m)), not a storable or bindable value.","triggerScenarios":"Passing the result of 'select entry(m) from ...' back as a query parameter; custom types trying to unwrap Map.Entry for binding; caching or batching code that round-trips entry() results into other operations.","commonSituations":"DTO assembly that feeds HQL projections into further queries; generic parameter-binding helpers accepting arbitrary objects; test fixtures reusing query results as inputs.","solutions":["Extract key and value from the entry and bind them as separate parameters","Project a DTO ('select new Dto(key(m), value(m))') instead of entry(m) when results will be reused","Treat entry() results as read-only — never persist, cache or rebind them"],"exampleFix":"// before\nvar e = (Map.Entry<String, String>) session\n        .createQuery(\"select entry(c.entries) from Config c\").getSingleResult();\nquery.setParameter(\"p\", e); // unwrap(Map.Entry) -> UnsupportedOperationException\n\n// after\nquery.setParameter(\"k\", e.getKey());\nquery.setParameter(\"v\", e.getValue());","handlingStrategy":"type-guard","validationCode":"static boolean bindableParameterValue(Object v) {\n    return !(v instanceof java.util.Map.Entry);\n}\n// guard generic binders: if (!bindableParameterValue(v)) decompose before setParameter","typeGuard":"static boolean isMapEntryProjection(Object value) {\n    return value instanceof java.util.Map.Entry;\n} // if true: extract key/value — never persist or bind the entry itself","tryCatchPattern":"try {\n    query.setParameter(\"p\", value);\n} catch (UnsupportedOperationException e) {\n    if (value instanceof Map.Entry<?, ?> entry) {\n        query.setParameter(\"k\", entry.getKey());\n        query.setParameter(\"v\", entry.getValue());\n    } else throw e;\n}","preventionTips":["Treat entry() results as read-only query projections","Convert entry() results to DTOs at the service boundary","Never cache or rebind Map.Entry instances into other queries"],"tags":["hibernate","orm","map","entry","unwrap"],"backgroundTag":"unsupported-type-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}