I am using the 'where' attribute in the <set> element quite successfully. However, for reasons of maintainability I would like to be able to externalise the content of the where clause so that I don't end up with a mapping file that, potentially, contains a large ugly 'where' attribute. I could then, at runtime, lookup the mapping and modify the 'where' clause programatically.
I looked at the Hibernate JavaDoc and it seems like I should be able to get to the mapping structure and, at the very least, display the where clause. When I attempt to do so however, using the following code, I just get a null value.
That problem aside, even if I could get at the where clause, it doesn't appear to be possible to modify it, i.e. there is no setter. Suggestions?
I realise that an alternative approach would be to use the query API to explicitly perform a query but I would very much like to fully leverage the lazy loading capabilities and stay away from unnecessary use of the query API when I don't strictly need to use it. As I said, the mapping file works perfectly as it is.
Thanks,
Scott.
Sample code:
PersistentClass pc = _config.getClassMapping(Order.class);
log.debug(pc.getName() + ", where = " + pc.getWhere());
PersistentClass pc = _config.getClassMapping(Item.class);
log.debug(pc.getName() + ", where = " + pc.getWhere());
Output:
ListMappings - Order, where = null
ListMappings - Item, where = null
Mapping:
<hibernate-mapping>
<class
name="Order"
table="ORDER"
proxy="Order">
<id name="id" column="ID">
<generator class="assigned"/>
</id>
<set name="licenseItems"
lazy="true"
where="PART_NUMBER IN ('555-6666', '111-2222')">
<key column="HEADER_ID"/>
<one-to-many class="Item"/>
</set>
</class>
</hibernate-mapping>
|