2

I have two tables: authors and books. Authors has two colums: int id, varchar authorName. Books has three colums: int id, varchar bookName, int authorId.

Now considering that I take the authorName as an input String filtering criteria how can I make hibernate only return the books by that certain author?

2
  • 1
    You mention sorting. Sorting means putting a number of items in a particular order. Do you actually want to sort anything here, or do you just want to filter by the name? Commented Aug 5, 2013 at 8:44
  • @TomAnderson I'm sorry, I meant filtering Commented Aug 5, 2013 at 8:48

1 Answer 1

7

How about

Criteria criteria = session.createCriteria( Book.class );
criteria.createCriteria( "author", "a");
criteria.add( Restrictions.eq( "a.authorName", "YOUR_INPUT"));
criteria.list();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.