{"record":{"id":"059024215640ef73","repo":"hibernate/hibernate-orm","slug":"cannot-parse-given-string-into-array-of-integers","errorCode":null,"errorMessage":"Cannot parse given string into array of integers. First and last character must be { and }","messagePattern":"Cannot parse given string into array of integers\\. First and last character must be (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java","lineNumber":89,"sourceCode":"\t\tsb.append( value[0] );\n\t\tfor ( int i = 1; i < value.length; i++ ) {\n\t\t\tsb.append( value[i] );\n\t\t\tsb.append( ',' );\n\t\t}\n\t\tsb.append( '}' );\n\t\treturn sb.toString();\n\t}\n\n\t@Override\n\tpublic int[] fromString(CharSequence charSequence) {\n\t\tif ( charSequence == null ) {\n\t\t\treturn null;\n\t\t}\n\t\tfinal List<Integer> list = new ArrayList<>();\n\t\tfinal char lastChar = charSequence.charAt( charSequence.length() - 1 );\n\t\tfinal char firstChar = charSequence.charAt( 0 );\n\t\tif ( firstChar != '{' || lastChar != '}' ) {\n\t\t\tthrow new IllegalArgumentException( \"Cannot parse given string into array of integers. First and last character must be { and }\" );\n\t\t}\n\t\tfinal int len = charSequence.length();\n\t\tint elementStart = 1;\n\t\tfor ( int i = elementStart; i < len; i ++ ) {\n\t\t\tfinal char c = charSequence.charAt( i );\n\t\t\tif ( c == ',' ) {\n\t\t\t\tlist.add( Integer.parseInt( charSequence, elementStart, i, 10 ) );\n\t\t\t\telementStart = i + 1;\n\t\t\t}\n\t\t}\n\t\tfinal int[] result = new int[list.size()];\n\t\tfor ( int i = 0; i < result.length; i ++ ) {\n\t\t\tresult[ i ] = list.get( i );\n\t\t}\n\t\treturn result;\n\t}\n\n\t@Override","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java#L71-L107","documentation":"IntegerPrimitiveArrayJavaType.fromString reconstructs an int[] from the array-literal string form Hibernate uses for array-valued columns ('{1,2}'). It throws IllegalArgumentException when the first and last characters are not '{' and '}' — the stored text is not an array literal in the expected shape.","triggerScenarios":"Reading an int[] attribute whose column text was written in a different format ('[1, 2]', '1;2'); hand-edited or migrated data; dialect/mapping changes that altered how the array is rendered to text.","commonSituations":"Databases without native ARRAY support storing arrays as text; ETL imports; switching between SqlTypes.ARRAY and varchar-backed mappings.","solutions":["Normalize stored data to the '{1,2}' form Hibernate writes","Add an AttributeConverter<int[], String> that tolerates other formats on read","Use a native ARRAY column with @JdbcTypeCode(SqlTypes.ARRAY) where supported","Keep a single writer for array-as-text columns"],"exampleFix":"// before: column text is '1;2;3' -> IllegalArgumentException\n\n// after: data normalized to Hibernate's literal form\nUPDATE tags SET ids = '{' || replace(ids, ';', ',') || '}' WHERE ids LIKE '%;%';","handlingStrategy":"validation","validationCode":"static boolean isArrayLiteral(CharSequence s) {\n    return s != null && s.length() >= 2\n            && s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}';\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize stored array text to the {1,2} literal form","Single writer for array-as-text columns","Use native ARRAY types where available"],"tags":["hibernate","array","parsing","integer","postgres-literal"],"backgroundTag":"array-literal-parse-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}