Hibernate version: 3.2.5
Mapping documents:
Code:
<class name="se.exder.marketplace.suppliers.SupplierEntity" table="supplier">
<id name="clientId" column="client_id" type="int" access="field">
<generator class="assigned" />
</id>
<property name="name" column="name" type="string" />
...
<map name="supplierAddresses" table="supplier_address" access="field" cascade="all-delete-orphan">
<key column="client_id" />
<composite-map-key class="se.exder.data.LocationCode">
<key-property name="codelistAgencyId" column="codelist_agency_id" type="string" access="field" />
<key-property name="locationId" column="location_id" type="string" access="field" />
</composite-map-key>
<element column="partner_exists" type="true_false" />
</map>
</class>
I need to query instances of the SupplierEntity class that has a specific key in its supplierAddresses Map. I cannot figure out how to do this with either HQL or Criteria. Currently I'm forced to use a native SQLQuery.
Here is what I have tried in HQL (only the where part differs):
1:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where (index(address).codelistAgencyId = ? and index(address).locationId = ?)
This causes a NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444).
2:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where (address.index.codelistAgencyId = ? and address.index.locationId = ?)
This causes "cannot dereference scalar collection element"
3:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where index(address) = ?
+ provide the composite key class (LocationCode) instance to setParameter(). This causes "SqlNode's text did not reference expected number of columns".
Any tips on how to do this in a "Hibernate fashion" are welcome.
Thanks in advance.