hibernate/hibernate-orm · error · MappingException
illegal identity column type
Error message
illegal identity column type
What it means
Informix identity columns come in only two flavors: 'serial' (Types.INTEGER) and 'bigserial' (Types.BIGINT). When Hibernate needs the SQL to retrieve the last generated identity value (getIdentitySelectString builds select dbinfo(...) ...) and the id column's java.sql.Types code is anything else, InformixIdentityColumnSupport throws this MappingException with 'illegal identity column type'.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/InformixIdentityColumnSupport.java:30
/**
* @author Andrea Boriero
*/
public class InformixIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final InformixIdentityColumnSupport INSTANCE = new InformixIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;
}
@Override
public String getIdentitySelectString(String table, String column, int type)
throws MappingException {
return "select dbinfo('" + switch ( type ) {
case Types.BIGINT -> "bigserial";
case Types.INTEGER -> "sqlca.sqlerrd1";
default -> throw new MappingException( "illegal identity column type" );
} + "') from informix.systables where tabid=1";
}
@Override
public String getIdentityColumnString(int type) throws MappingException {
return switch ( type ) {
case Types.BIGINT -> "bigserial";
case Types.INTEGER -> "serial";
default -> throw new MappingException( "illegal identity column type" );
} + " not null";
}
@Override
public boolean hasDataTypeInIdentityColumn() {
return false;
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Map the identifier as Integer/int or Long/long so Types.INTEGER/BIGINT applies.
- If the column type must stay smallint/numeric, switch the generator to SEQUENCE or the enhanced 'sequence'/'table' generator.
- Let the application assign ids (assigned/natural generator) instead of the database.
- If the schema really is serial-compatible, force the JDBC type with @JdbcTypeCode(SqlTypes.INTEGER) - but changing the Java type to Integer/Long is the clean fix.
Example fix
// before - Short maps to SMALLINT, not serial-compatible @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Short id; // after - maps to Types.BIGINT -> bigserial @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
Defensive patterns
Strategy: validation
Validate before calling
// Before bootstrap on Informix, ensure identity ids are Integer or Long
Class<?> idType = reflectIdType(MyEntity.class);
if (!Integer.class.equals(idType) && !Long.class.equals(idType)
&& !int.class.equals(idType) && !long.class.equals(idType)) {
throw new IllegalStateException("Informix identity requires Integer/Long id, got " + idType);
} Type guard
static boolean informixIdentityCompatible(Class<?> idJavaType) {
return idJavaType == Integer.class || idJavaType == int.class
|| idJavaType == Long.class || idJavaType == long.class;
} Try / catch
try {
sessionFactory = new Configuration().addAnnotatedClass(MyEntity.class).buildSessionFactory();
} catch (MappingException e) {
if (e.getMessage().contains("illegal identity column type")) {
// fix the @Id type or switch generator strategy, then rebuild
}
throw e;
} Prevention
- Keep @GeneratedValue(IDENTITY) ids as Integer or Long
- Add a mapping smoke test that builds the SessionFactory in CI for each target dialect
- Prefer sequences for non-integer primary keys
When it happens
Trigger: An entity mapped with @GeneratedValue(strategy = GenerationType.IDENTITY) (or the legacy 'identity' generator) whose identifier Java type resolves to a JDBC type other than INTEGER/BIGINT - e.g. Short/smallint, String, BigDecimal/numeric. Thrown when the mapping is bound (SessionFactory build), during export of the dbinfo select string.
Common situations: Porting an app from another database where identity on smallint or numeric worked; legacy Informix schemas; accidentally mapping the @Id as Short or java.math.BigInteger; changing an id type during a refactor and failing fast at bootstrap.
Related errors
- Generator '%s' declares generated type '%s', which is not as
- Null id generated for entity '%s'
- Attribute was not a Map : ${collectionMemberType}
- Unable to create AttributeConverter instance
- illegal identity column type
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e8dd3cb5c2eda010.
Report an issue: GitHub.