-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Query by natural id Warning message
PostPosted: Tue Mar 27, 2012 8:44 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.