I apologize for not including any code. Obviously my question is unclear without an example. So here goes:
I pulled an example from
here and modified it a bit. I'm ignoring the part about lazy loading and changing the classes around.
So here's the deal. Suppose we're storing City objects and each City has a Name, and a HashMap with keys of Streets and Values of PostalCodes.
In this case, my goal would be to pull all the Cities with a street called "Embarcadero".
Code:
<hibernate-mapping package="com.xebia.map" default-access="field">
<class name="City">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<map name="postalCodes">
<key column="id"/>
<index column="streetName" type="string">
<element column="zipCode" type="string">
</map>
</class>
</hibernate-mapping>
City city1 = new City("Oakland");
city.add("Hegenberger", "94606");
city.add("Outlook", "94605");
city.add("Embarcadero", "94603");
City city2 = new City("San Francisco");
city.add("Embarcadero", "94111");
city.add("Market", "94113");
city.add("Castro", "94102");
Session session = factory.openSession();
Transaction transaction = session.beginTransaction();
session.save(city1);
session.save(city2);
transaction.commit();
session.close();
session = factory.openSession();
//now will this pull back both cities?
City exampleCity = new City("Example");
exampleCity.add("Embarcadero", null);
Example example = Example.create(exampleCity).enableLike();
List cities1 = session.createCriteria(Person.class)
.add(example).list();
//or will this pull back both cities?
List cities2 = session.createCriteria(City.class)
.add(Restrictions.like("postalCodes.streetName", "Embarcadero"))
.list();
//OR will I need to just break down and use HQL?
//and is this HQL even right?
List cities3 = session.createQuery("select c from City c " +
"join fetch c.postalCodes " +
"where c.postalCodes.streetName = :streetName")
.setParameter("streetName", "Embarcadero");