I'm trying to write a general-purpose search function for my app and am looking into the Criteria API for doing so. Its ability to dynamically generate searches is rather powerful and attractive.
However, I've hit a few snags. It's easy enough to say do simple equality checks, gt, lt, and "in" predicates, but past that seems a bit arcane.
I have two cases I need to figure out:
1. I have a Person object that has a set of email addresses. To complicate matters, this isn't actually a set, but a java Map between address types and addresses (such as "home", "other", "work" email addresses). These are mapped like so:
Code:
<map name="emailAddressesInternal" table="Person_EmailAddresses">
<key column="person_id" not-null="true" />
<map-key-many-to-many column="addresstype_id" class="esta.dataobjects.AddressType" />
<element column="email_address" type="string" />
</map>
How can I say "find me all people with email address
bob@example.com"?
2. If there is a one-to-many relationship between an object A (one) and an object B (many), how do I make a criteria search for all B's that are related to A?
Basically I want to know how to do object-equality criteria (based on id), and how to do searching within a set or map.
Thanks in advance.