Hi,
To illustrate a simple query on the MyBook hierarchy.
Code:
Query q = mEntityManager.createQuery("from MyBook mb");
List<MyBook> res = q.getResultList();
for(MyBook b : res) {
if(b instanceof LibraryBook) {
LibraryBook libBook = (LibraryBook)b;
// do stuff
}
else if(b instanceof PurchaseBook) {
PurchaseBook pBook = (PurchaseBook)b;
// do stuff
}
}
This is only a simple example that queries the MyBook structure only, but it is very easy to change the query to something like this:
Code:
Query q = mEntityManager.createQuery("from BorrowOut b INNER JOIN FETCH b.borrowOutBook ob");
The above query joins the 2 entities, and eagerly fetchs the MyBook sturcture, you can then apply the same logic as in my first example.
I hope this helps, and the query should be independent from the inheritence strategy being used (it should work with all).
Cheers,
Andy