I have a collection that maps from Uservehicle to Vehicle. Each Uservehicle will have a number of vehicles in it's Vehicles collection. The definition I have used passes the Uservehicle id to the query to select all vehicles for the collection. I believe this is the default implementation.
However, due to the complexity of my data I need to pass the usercapid field as the parameter in the query to fetch the collection, is there a way to do this? Should I be using a different relationship? I have tried <id foreign-key="usercapid" /> but this does not appear to be the correct use of this attribute.
Uservehicle.hbm.xml
Code:
<class name="Cara.BusinessObjects.Uservehicle,Cara" table="uservehicle">
<id name="Id" column="id" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property column="userid" type="Int32" name="Userid" not-null="true" />
<property column="usercapid" type="Int32" name="Usercapid" not-null="true" update="false" />
<property column="modified" type="DateTime" name="Modified" not-null="true" />
<set name="Vehicles" >
<key column="capid" />
<one-to-many class="Cara.BusinessObjects.Vehicle,
Cara" />
</set>
</class>
DebugCode:
2006-03-15 16:41:12,406 DEBUG 2536 NHibernate.Impl.SessionImpl - resolving associations for: [Cara.BusinessObjects.Uservehicle#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - creating collection wrapper:[Cara.BusinessObjects.Uservehicle.Vehicles#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - done materializing entity [Cara.BusinessObjects.Uservehicle#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - initializing non-lazy collections
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - initializing collection [Cara.BusinessObjects.Uservehicle.Vehicles#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - checking second-level cache
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - collection not cached
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands :1
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :vehicles0_.capid
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Type.NullableType - binding '8160' to parameter: 0
2006-03-15 16:41:12,421 INFO 2536 NHibernate.Loader.Loader - SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :p0
2006-03-15 16:41:12,421 INFO 2536 NHibernate.Impl.BatcherImpl - Preparing SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :p0
2006-03-15 16:41:12,437 DEBUG 2536 NHibernate.Impl.BatcherImpl - Opened Reader, open Readers :1
2006-03-15 16:41:12,437 DEBUG 2536 NHibernate.Loader.Loader - result set contains (possibly empty) collection: [Cara.BusinessObjects.Uservehicle.Vehicles#8160]
Thanks