The situation is Users have Vases. But the vases maybe broken.
The tables look like this
The mappings look like this
But I need to have methods getBrokenVases() and getGoodVases() in the User class. Also for these calls I don't want all Vases come to the web server from the DB but only broken or good ones (for performance reasons). What approach should I take.
Approach 1 : I could think of is I should have two Sets in class User and use a "where" attribute of mapping <set>. But is it true that in "where" attribute I can only put in native sql. How do I use HSQL ?
Approach 2 : Use filters. This seems like a new approach. But here too can I only use native sql.
One other problem I faced was the generated SQL won't execute because in the where clause I used table names. But else where Hibernate used aliases. So the query wouldn't run unless I use alias in where clause. So how do I know what alias Hibernate generates? Is this only a problem with Derby db.
Please suggest a good solution to this problem. I would prefer to use HSQL.
What about inheritance, create subclasses of Vase, and then use the boolean as the discrimintor value. I will let you find out how to do that on your own, as this is a coursework homework that you are doing. Good Luck. Your thoughts aren't off either, but I think inheritence is the easiest, once you get past the terms.