hibernate/hibernate-orm · error · AnnotationException

Named query hint [" + hintName + "] is not a boolean: " + qu

Error message

Named query hint [" + hintName + "] is not a boolean: " + queryName

What it means

QueryHintDefinition.getBoolean reads a hint from the named query's hintsMap via ConfigurationHelper.getBoolean; if the stored value cannot be interpreted as a boolean it throws, and QueryHintDefinition wraps it in AnnotationException naming the hint and query. This happens while named-query definitions are initialized at bootstrap, not when the query runs.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java:75

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Generic access

	@Nonnull
	public Map<String, Object> getHintsMap() {
		return hintsMap;
	}

	@Nullable
	public String getString(@Nonnull String hintName) {
		return (String) hintsMap.get( hintName );
	}

	public boolean getBoolean(@Nonnull String hintName) {
		try {
			return ConfigurationHelper.getBoolean( hintName, hintsMap );
		}
		catch (Exception e) {
			throw new AnnotationException( "Named query hint [" + hintName + "] is not a boolean: " + queryName, e );
		}
	}

	@Nullable
	public Boolean getBooleanWrapper(@Nonnull String hintName) {
		try {
			return ConfigurationHelper.getBooleanWrapper( hintName, hintsMap, null );
		}
		catch (Exception e) {
			throw new AnnotationException( "Named query hint [" + hintName + "] is not a boolean: " + queryName, e );
		}
	}

	@Nullable
	public Integer getInteger(@Nonnull String hintName) {
		try {
			return ConfigurationHelper.getInteger( hintName, hintsMap );
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use literal "true" or "false" for boolean hints.
  2. Check the exact hint key — a misspelled name can route a non-boolean value into a boolean slot.
  3. If hints come from configuration, normalize them to true/false before they reach the mapping.

Example fix

// before
@NamedQuery(
    name = "Person.findActive",
    query = "from Person p where p.active = true",
    hints = @QueryHint(name = "org.hibernate.cacheable", value = "yes"))

// after
@NamedQuery(
    name = "Person.findActive",
    query = "from Person p where p.active = true",
    hints = @QueryHint(name = "org.hibernate.cacheable", value = "true"))
Defensive patterns

Strategy: validation

Validate before calling

// test-time: validate every declared boolean hint parses
for (NamedQuery q : allNamedQueries()) {
    for (QueryHint h : q.hints()) {
        if (isBooleanHint(h.name())) {
            Boolean.parseBoolean(h.value()); // throws nothing on bad input, so assert explicitly:
            assertTrue(h.value().equals("true") || h.value().equals("false"),
                h.name() + " must be true/false, was: " + h.value());
        }
    }
}

Type guard

boolean isValidBooleanHint(String value) {
    return "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
}

Try / catch

try {
    metadata = sources.buildMetadata();
} catch (AnnotationException e) { // wraps the underlying parse failure, names hint + query
    failBuild("Bad boolean query hint: " + e.getMessage() + " cause=" + e.getCause());
}

Prevention

When it happens

Trigger: A boolean hint such as org.hibernate.cacheable or org.hibernate.readOnly on @NamedQuery/@QueryHint with a value ConfigurationHelper cannot parse, e.g. "yes", "1" (depends on parser), or a misspelled string; jakarta.persistence.query.timeout-style numeric strings routed to a boolean getter would also fail.

Common situations: Writing @QueryHint(name = "org.hibernate.cacheable", value = "yes"); copying hint examples with Y/N conventions from other stacks; passing property-file values (on/off) that the boolean parser rejects; typos like "ture".

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/d25eacc1b25338cf. Report an issue: GitHub.