java - Hibernate Criteria could not resolve property when it's there -


this 1 has me stumped. have idea how criteria works reason query giving me issues not being able find property when it's there.

shelf.java

@entity @table(name="bookshelf") public class shelf {  @id private int shelfid; private string shelfname; private string shelftype; @onetomany(mappedby="shelf",cascade=cascadetype.all) private set<book> book = new hashset<book>(0);  //getters&setters here 

book.java

@entity @table(name="books") public class book {  @id private int bookid; private string bookname; private string bookstate; @manytoone(cascade=cascadetype.all) private shelf shelf;      //getters&setters here 

here's criteria query:

criteria criteria = session.createcriteria(book.class)                     .add(restrictions.eq("shelf.shelfid", booklocid))                     .add(restrictions.ne("shelf.shelftype", "table"))                     .add(restrictions.ne("bookstate", "requested"); 

the problem middle restriction. can't find shelftype finds shelfid fine. thank help!

it finds shelfid fine, because key of association , therefore there no join required query see id. if want add restriction other property, must join shelf association, instance this:

criteria criteria = session.createcriteria(book.class)          // joins shelf association , creates alias 'shelf'          .createalias("shelf", "shelf")          .add(restrictions.eq("shelf.shelfid", booklocid))          .add(restrictions.ne("shelf.shelftype", "table"))          .add(restrictions.ne("bookstate", "requested"); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -