hibernate/hibernate-orm · error · SemanticException
Illegal unit conversion " + this + " to " + unit
Error message
Illegal unit conversion " + this + " to " + unit
What it means
Error "Illegal unit conversion " + this + " to " + unit" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/common/TemporalUnit.java:181
* the smallest unit of fractional seconds, either milliseconds
* or microseconds. We define this value in order to avoid
* repeatedly converting between {@link #NANOSECOND}s and a
* unit that the database understands. On some platforms this
* is also used to avoid numeric overflow.
*
* @see Dialect#getFractionalSecondPrecisionInNanos()
*/
NATIVE;
public String conversionFactor(TemporalUnit unit, Dialect dialect) {
if ( unit == this ) {
//same unit, nothing to do
return "";
}
if ( unit.normalized() != normalized() ) {
throw new SemanticException("Illegal unit conversion " + this + " to " + unit);
}
long from = normalizationFactor( dialect );
long to = unit.normalizationFactor( dialect );
if ( from == to ) {
// the units represent the same amount of time
return "";
}
else {
// if from < to, then this unit represents a
// smaller amount of time than the given unit
// we are converting to (so we're going to
// need to use division)
return (from < to ? "/" : "*")
+ factorAsString(from < to ? to / from : from / to);
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Convert only between compatible temporal units (e.g. not months to seconds).
- Perform the conversion in application code with explicit logic.
When it happens
Trigger: A runtime precondition of the Hibernate API is violated.
Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ad02e9a418bd6b40.
Report an issue: GitHub.