Solved: Hibernate not autoscanning entity classes
Posted in Technical on February 10th, 2026 by p14nd4I recently had to update an old Java (.war) JPA/Hibernate project (from Hibernate 5.4 to 7.2, among other things), and ran into org.hibernate.query.sqm.UnknownEntityException: Could not resolve root entity 'Foo' issues at runtime. (My classes were annotated with @Entity and named correctly.) Relatedly, when I tried to set jakarta.persistence.schema-generation.database.action to CREATE or similar (e.g., for testing in a new environment), it wouldn’t generate my tables.
This used to work, and while I discovered that explicitly adding <class>org.example.Foo.Bar</class>-type entries to my persistence.xml worked around the issue, that was dissatisfying, since everything indicated this should “just work” (as it had before), and I’d rather avoid adding additional touch-points that inevitably will be missed when some new @Entity class is added in the future.