This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
The first thing you need is a mind shift. So, you've got tablea and tableb and tablec? How does that matter? I could have one class mapped across all three tables. Or ten-thousand classes mapped to those three tables? You are thinking about tables. Sure, they are the underpinning of your data, but Hibernate and the Criteria API is all about your OBJECTS.
What classes to you have?
TableA and TableB? Maybe a User and an Address? Maybe a Course and Students? What are the OBJECTS?
Then, when you have the objects, you can create your criteria query.
So, a user has an address, and you want to final all Users that live in Toronto? Do this:
Now, do a criteria Example query based on the User. Since the example provided has a city address of Toronto, you'll get back all users that live in Toronto.
What are the names of the underlying tables in this User-Address example, and how many tables are there? Well, there are actually 5000 tables! Yeah, 5000! But we don't care, because that is all mapped behind the scenes by crazy database admins. All we care about is the OBJECTS and their relationships.
Here's an example of some Criteria code, just to give you an idea of how it might work:
If you're interested, you can find more in this tutorial of mine: