Hibernate version:3.0.5
Mapping documents:
<class name="Customer" ...>
...
<set name="addressList" inverse="true">
<key column="core_customer_identifier"/>
<one-to-many class="AddressLink"/>
</set>
</class>
<class name="AddressLink" ...>
<property name="mailingAddressFlag" type="character" ... />
<property name="shippingAddressFlag" type="character" ... />
...
<many-to-one name="customerAddress" ... class="CustomerAddress" ... />
</class>
<class name="CustomerAddress" ...>
<property name="street" ... />
<property name="city" ... />
<property name="state" ... />
<property name="primaryFlag" .../>
...
</class>
Name and version of the database you are using: SQL Server 2000
Hello all. I've been searching all over the forums and such and even read through some of the Hibernate source, but I'm at a loss here. I think that what I want to do isn't possible, but I'm still holding out some hope. Prove me wrong!
I have a schema where there is a Customer table that has Addresses. However, it's linked through a mapping table. That mapping table isn't a basic mapping table though, it actually has the flags to indicate what type of address it is, so it contains important data, but it is irrelevant if it doesn't have an address. I know this is strange and they should have just put the indicators on the address table itself, but it's legacy stuff that I get to deal with... :)
At any rate, I would like to lazy load the addresses, but I also need to apply a filter to the addresses retrieved (sometimes) in that I only want to retrieve primary addresses. However, the primary flag is on the address table, not the link table.
I really want this to be lazy loaded. I've been using the Filter objects to great benefit, and I love how the filters work. However, I'm at a loss as to how or if it's even possible to filter by the value in a table that is associated with your collection association.
Namely, I want to be able to use a filter to only return AddressLink rows where there is an active Address. So, if it would work, then I'd like a filter something like the following on my Customer mapping:
<filter name="address_active"
condition="customerAddress.primaryFlag='Y'"/>
Obviously that won't work, because those aren't column names and it's invalid sql. However, is there a way to do what I'm want and still support lazy fetching? I imagine I could use a sub-criteria and declare it with a left-join, but that would be an eager load, which I would just rather avoid, if possible.
|