Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0
Mapping documents:
<class name="Party">
.....
<set name="addresses" table="PARTY_ADDRESS" >
<key column="PARTY_ID" not-null="true"/>
<one-to-many class="PartyAddress"/>
</set>
</class>
<class name="PartyAddress" table="PARTY_ADDRESS" >
.....
<many-to-one name="address" class="Address"
column="ADDRESS_ID" />
</class>
<class name="Address" table="ADDRESS">
<id name="addressId" column="ADDRESS_ID">
<generator class="sequence">
<param name="sequence">PARTY_ADDRESS_ID_SEQ</param>
</generator>
</id>
<property name="addressType" type="string">
<column name="ADDRESS_TYPE" sql-type="VARCHAR2"/>
</property>
<joined-subclass name="GeographicAddress"
table="GEOGRAPHIC_ADDRESS">
<key column="ADDRESS_ID"/>
......
<property name="city" column="CITY"/>
<property name="zipCode" column="ZIP_1"/>
</joined-subclass>
<joined-subclass name="TelecomAddress"
table="TELECOM_ADDRESS">
<key column="ADDRESS_ID"/>
<property name="phoneNumber" type="long">
<column name="PHONE" sql-type="number"/>
</property>
</joined-subclass>
</class>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
Criteria criteria =
session.createCriteria(PartyAssociation.class)
.createCriteria("party")
.createCriteria("addresses")
.createCriteria("address")
.add(Restrictions.and(Restrictions.eq("city", "Albany"),
Restrictions.eq("phoneNumber", "989898")));
System.out.println(criteria.list().size());
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
Oracle 10g
I would like to retrieve all party objects which have a specified Geographic Address city property (e.g. albany) AND a specified phone number. Is this possible with HQL or Criteria querying? Or do i have to go for native SQL and intersects? The above criteria query returns Zero records as expected.
Have been stuck on this issue for quite sometime now.