gorm-hibernate5
gorm-hibernate5 copied to clipboard
Hibernate's legacy org.hibernate.Criteria API is deprecated
I don't know if this belongs here or in the grails-data-mapping/grails-datastore-gorm-hibernate-core but these are WARN level messages, which we can disable using logback but the codebase should probably be updated.
The full message is:
HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
Yes we are aware. We plan to move to JPA for GORM 7.0 but since it is a major breaking change that is for a future release.
See https://github.com/grails/grails-data-mapping/issues/941
I still see the logs with grails 4 and gorm 7.0.8
This issue still happens on grails 5 with gorm 7.2.1
This is the data service code which triggers the warning
@Service(User)
interface UserDataService {
@ReadOnly
User findByUsername(String username);
@ReadOnly
User findById(String id);
@Transactional
User saveUser(User user);
}
When findByUsername
method is called, then the follow warning shows up
04-16 11:20:57.278 WARN [TaskScheduler-1] org.hibernate.internal.SessionImpl.createCriteria [SessionImpl.java:1832]
HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
Here is the stacktrace, the code inside AbstractFindByFinder.java
line 44 calls HibernateSession.java
then calles org.hibernate.internal.SessionImpl.createCriteria
method, then output the warning

And there is the exact line of code HibernateSession.createQuery
(line 186) which calls the legacy createCriteria
hibernate API

Is there any good workaround for the this problem (HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
) other than adding <logger name="org.hibernate.orm.deprecation" level="OFF"/>
to conf/logback.xml
as this might hide other problems.
We currently face the problem with a Grails 5.2.5 app (with org.grails.plugins:hibernate5:7.3.0). We get this error on every create of a domain object as the unique: true
constraint causes this warning :-(
Having the domain class
class Issue55 {
String name
static constraints = {
name(blank: false, unique: true)
}
}
and having the following BootStrap.groovy
file
import grails.gorm.transactions.Transactional
class BootStrap {
def init = { servletContext ->
doInit()
}
@Transactional
void doInit() {
log.info"START BOOTSTRAP --------------------------------------------------------------------------------"
new Issue55(name: "test-it").save(failOnError: true, flush: true)
log.info"END BOOTSTRAP--------------------------------------------------------------------------------"
}
results in the log
2023-01-25 18:02:16.569 INFO --- [ restartedMain] dummy.BootStrap : START BOOTSTRAP --------------------------------------------------------------------------------
2023-01-25 18:02:16.688 WARN --- [ restartedMain] org.hibernate.orm.deprecation : HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
2023-01-25 18:02:16.730 INFO --- [ restartedMain] dummy.BootStrap : END BOOTSTRAP--------------------------------------------------------------------------------
Imagine if you add a few thousand object to the database you get a lot of WARN messages.
Thanks for any helpful advice
For my applications I have added the line to the logback.groovy
logger('org.hibernate.orm.deprecation', OFF)