这是我的数据库结构。多对多的关系。我想选择写过同一本书的作者。使用 SQL,我做到了。如何使用 HQL?
Query query = session.createSQLQuery("SELECT FirstName, LastName FROM authors, books, author_book as ab WHERE ab.authorID=authors.authorID AND ab.bookID = books.bookID AND ab.bookID = :id");
query.setInteger("id", 1);
List list = query.list();
Iterator<Object[]> iter = list.iterator();
while (iter.hasNext()) {
Object[] obj = iter.next();
System.out.println(obj[0] + " " + obj[1]);
}