Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate's legacy org.hibernate.Criteria API is deprecated #55

Open
olliefreeman opened this issue Sep 27, 2017 · 6 comments
Open

Hibernate's legacy org.hibernate.Criteria API is deprecated #55

olliefreeman opened this issue Sep 27, 2017 · 6 comments

Comments

@olliefreeman
Copy link

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

@graemerocher
Copy link
Member

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.

@graemerocher
Copy link
Member

See grails/grails-data-mapping#941

@purpleraven
Copy link
Contributor

I still see the logs with grails 4 and gorm 7.0.8

@xqliu
Copy link

xqliu commented Apr 16, 2022

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

image

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

image

@m4rc77
Copy link

m4rc77 commented Jan 25, 2023

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

@purpleraven
Copy link
Contributor

For my applications I have added the line to the logback.groovy

logger('org.hibernate.orm.deprecation', OFF)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants