hibernate/hibernate-orm · error · IllegalArgumentException
Cannot parse given string into array of integers. First and
Error message
Cannot parse given string into array of integers. First and last character must be { and } What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerPrimitiveArrayJavaType.java:89
sb.append( value[0] );
for ( int i = 1; i < value.length; i++ ) {
sb.append( value[i] );
sb.append( ',' );
}
sb.append( '}' );
return sb.toString();
}
@Override
public int[] fromString(CharSequence charSequence) {
if ( charSequence == null ) {
return null;
}
final List<Integer> list = new ArrayList<>();
final char lastChar = charSequence.charAt( charSequence.length() - 1 );
final char firstChar = charSequence.charAt( 0 );
if ( firstChar != '{' || lastChar != '}' ) {
throw new IllegalArgumentException( "Cannot parse given string into array of integers. First and last character must be { and }" );
}
final int len = charSequence.length();
int elementStart = 1;
for ( int i = elementStart; i < len; i ++ ) {
final char c = charSequence.charAt( i );
if ( c == ',' ) {
list.add( Integer.parseInt( charSequence, elementStart, i, 10 ) );
elementStart = i + 1;
}
}
final int[] result = new int[list.size()];
for ( int i = 0; i < result.length; i ++ ) {
result[ i ] = list.get( i );
}
return result;
}
@OverrideView on GitHub (pinned to fad1729dce)
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
Example fix
// before: column text is '1;2;3' -> IllegalArgumentException
// after: data normalized to Hibernate's literal form
UPDATE tags SET ids = '{' || replace(ids, ';', ',') || '}' WHERE ids LIKE '%;%'; Defensive patterns
Strategy: validation
Validate before calling
static boolean isArrayLiteral(CharSequence s) {
return s != null && s.length() >= 2
&& s.charAt(0) == '{' && s.charAt(s.length() - 1) == '}';
} Prevention
- Normalize stored array text to the {1,2} literal form
- Single writer for array-as-text columns
- Use native ARRAY types where available
When it happens
Trigger: 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.
Common situations: Databases without native ARRAY support storing arrays as text; ETL imports; switching between SqlTypes.ARRAY and varchar-backed mappings.
Related errors
- Cannot parse given string into array of Doubles. First and l
- Cannot parse given string into array of Floats. First and la
- Cannot parse given string into array of Shorts. First and la
- Cannot parse given string into array of strings. First and l
- Cannot parse given string into array of strings. Outside of
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/059024215640ef73.
Report an issue: GitHub.