Hi,
I've run into a wall with an issue that I hope you can help with. I have a parent object Page with a set association assets. In order to achieve a binding of Page to Assets in different "zones" I had to create a composite-element in the assets set association.
I now need to query for 2 lists. List 1 is all assets that have a binding in PageAsset. List 2 is all assets that do not have a binding in PageAsset.
In SQL this is a straightforward inner join between asset.id and pageasset.asset_id to get List 1. Below is what I have tried but I am told that PageAsset is not mapped, presumably because it's a composite-element.
List 2 I have not tried a query for yet.
Hibernate version: 3.0
Mapping documents:
Code:
<set name="assets" table="tblPageAssets" lazy="false" cascade="none">
<key column="page_id" not-null="true" />
<composite-element class="PageAsset">
<many-to-one name="asset" class="Asset" column="asset_id" cascade="all" />
<property name="peerPosition" column="peer_position" type="int" not-null="true" />
<property name="zone" column="zone" type="string" not-null="true" />
</composite-element>
</set>
Code between sessionFactory.openSession() and session.close():Code:
public List<Asset> getAssets() {
return (List<Asset>) getHibernateTemplate().find(
"from Asset asset, PageAsset pa " +
"where asset.id = pa.asset.id"
);
}
Debug level Hibernate log excerpt:
PageAsset is not mapped