is there a shorter hql query available for this function?
I thought of something like "from Book where authors.name like ?" instead of "from Author where name like ?" where i need to loop through the authors.
Function:
Code:
public List getBooksByAuthor(String author) throws DataAccessException
{
List authorList= getHibernateTemplate().find("from Authors where name like ?", author);
List bookList= new java.util.ArrayList();
for (int i=0;i<authorList.size();i++)
{
Author myAuthor= (Author)authorList.get(i);
bookList.add(myAuthor.getBook());
}
return bookList;
}
Hibernate Mapping:
Code:
<class name="Book" table="book">
<id name="id" column="id" unsaved-value="0">
<generator class="increment" />
</id>
<property name="name" column="name" not-null="true" />
<set name="authors" cascade="all" inverse="false" lazy="false">
<key column="book_id"/>
<one-to-many class="Author"/>
</set>
</class>
<class name="Author" table="author">
<id name="id" column="id" unsaved-value="0">
<generator class="increment" />
</id>
<property name="name" column="name" not-null="true" />
<many-to-one name="book" class="Book" column="book_id" insert="false"/>
</class>