Code:
@Entity
public class Shelf {
public int shelfID;
public List<Book> books;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
public int getShelfID() {
return shelfID;
}
public void setShelfID(int _shelfID) {
shelfID=_shelfID;
}
@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinTable(name="SHELF_BOOK",
joinColumns={@JoinColumn(name="SHELF_ID")},
inverseJoinColumns={@JoinColumn(name="BOOK_ID")})
public List<book> getBooks() {
return books;
}
public void setBooks(List<Book> _books) {
books=_books;
}
}
Code:
@Entity
public class Book {
public int bookID;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
public int getBookID() {
return bookID;
}
public void setBookID(int _bookID) {
bookID=_bookID;
}
}
now my question is :
how can I query for a shelf with shelfID=3 and bookID=4.
something like
Quote:
select s from Shelf s where s.books.id=4 and s.id=3
[/quote]