I have ManyToMany relationship between Author and Book.
table :AUTHOR
id | name
table :ASSIGN
*id | author_id | book_id*
table : BOOK
id | title
But I am using not standart ManyToMany mapping, I am using next
class Book
{
@Id
long id;
String title;
@OneToMany
List<Assign> authors;
}
class Assign
{
@Id
long id;
@ManyToOne
Book book
@ManyToOne
Author author;
}
class Author
{
@Id
long id;
String name;
@OneToMany
List<Assign> books;
}
What is query to get all Books for Author’s name? Also What is query to get all Books’ names for Author’s name?
You simply have two OneToMany associations. You just need to use joins in your query, as described in the Hibernate documentation over HQL.
The second query is the same, except you just want the book names:
Side note: you shouldn’t name your collection of Assigns
booksorauthors: it’s very confusing. Name itassigns.