I have a problem of creating NamedQuery with Hibernate. The problem is I need to select a list of Books not appearing in Orders. My classes looks something like this:
@Entity
@NamedQueries({ @NamedQuery(name = "Book.findAvailable",
query = "SELECT b FROM Book b WHERE b.id not in ????????") })
public class Book {
@Id
@GeneratedValue
private Long id;
......
and Order:
@Entity(name = "orders")
public class Order {
@Id
@GeneratedValue
private Long id;
@ElementCollection
private List<Book> items;
.....
As you see, I keep my Books in order in a list. The Query I need should pull out all the books from the DB which don't apear in any order. Any help is appreciated. Many thanks.