Hi,
According to the latest manual, loading object through natural id is supposed to be more efficient.
However, I get a warning message when I load an object in this way:
Code:
SessionImpl.tryNaturalIdLoadAccess(1603) | Session.byNaturalId(nl.project.model.User) should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria
I have the code in line with the example from the manual
Code:
User user = (User) getSessionFactory().getCurrentSession()
.createCriteria(User.class)
.add(
Restrictions.naturalId().set("email", email)
)
.setFetchMode("roles", FetchMode.JOIN)
.setCacheable(true)
.setCacheRegion(CacheRegion.QUERY)
.uniqueResult()
;
Am I doing something wrong or is the documentation outdated?
I also tried to use
Code:
User user = (User) getSessionFactory().getCurrentSession()
.byNaturalId(User.class)
.using("email", email)
.load()
This works, however, it doesn't allow me to setCacheable, or to join in relations. I just wonder which is the recommended way if any.
Kind regards,
Marc