hibernate/hibernate-orm · error · IllegalArgumentException
not null makes no sense for in expression
Error message
not null makes no sense for in expression
What it means
InFragment is the legacy builder for SQL IN-list restrictions (used by old Criteria translators and discriminator restrictions). It understands a NULL sentinel — rendered as 'col is null or col in (...)' — but a NOT_NULL sentinel is meaningless inside an IN expression, so encountering it in the default branch throws IllegalArgumentException. The restriction as composed is logically impossible.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/sql/InFragment.java:95
if ( NOT_NULL.equals( value ) ) {
buf.append( " is not null" );
}
else {
buf.append( '=' ).append( value );
}
}
return buf.toString();
}
default: {
boolean allowNull = false;
for ( Object value : values ) {
if ( NULL.equals( value ) ) {
allowNull = true;
}
else {
if ( NOT_NULL.equals( value ) ) {
throw new IllegalArgumentException( "not null makes no sense for in expression" );
}
}
}
if ( allowNull ) {
buf.append( '(' )
.append( columnName )
.append( " is null or " )
.append( columnName )
.append( " in (" );
}
else {
buf.append( columnName ).append( " in (" );
}
for ( Object value : values ) {
if ( !NULL.equals( value ) ) {
buf.append( value );View on GitHub (pinned to fad1729dce)
Solutions
- Remove the NOT_NULL sentinel from the value list — never pass InFragment.NOT_NULL to an IN fragment
- Express 'is not null' with a dedicated isNotNull restriction/condition instead of the IN list
- Migrate legacy Hibernate Criteria usage to JPA Criteria or JPAQL, which handle null semantics explicitly
Example fix
// before (legacy internal fragment usage)
InFragment frag = new InFragment();
frag.setColumnName("region_code");
frag.addValue(InFragment.NOT_NULL); // IllegalArgumentException
// after
frag.addValue("EMEA").addValue("APAC");
// and use a separate "region_code is not null" condition where needed Defensive patterns
Strategy: validation
Validate before calling
// if you must use InFragment, filter invalid sentinels first
for (Object value : values) {
if (!InFragment.NOT_NULL.equals(value)) {
fragment.addValue(value); // NULL is fine; NOT_NULL never is
}
} Prevention
- Never pass InFragment.NOT_NULL to an IN-list fragment
- Express 'is not null' with a dedicated condition, not the IN restriction
- Migrate legacy Criteria code to JPA Criteria to avoid raw fragment plumbing
When it happens
Trigger: Legacy Criteria/Criterion code or custom restrictors plumbing InFragment.NOT_NULL through addValue(); discriminator-based filters reusing InFragment constants; ported code that used NOT NULL semantics from a different fragment type.
Common situations: Maintaining pre-JPA-Criteria code paths; custom dialect or restriction helpers built on org.hibernate.sql fragments; copying InFragment usage from old forum code.
Related errors
- Expected table group with table joins to have an entity type
- Query string is not a mutation
- Expecting a selection query, but found '{}'
- Select item was of wrong entity type
- Select item was not an entity type
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e536b0794d643ee8.
Report an issue: GitHub.