I have 4 objects: Trade, PhysicalTrade, TradeLeg, PhysicalTradeLeg. Trade has a bag of TradeLegs, and PhysicalTrade has a bag of PhysicalTradeLegs. PhysicalTrade is a subclass extending Trade, and PhysicalTradeLeg is a joined subclass extending TradeLeg.
When I run this HQL:
from BP.IST.Domain.Trade.PhysicalTrade t join fetch t.TradeLegs l where l.PipelineId IN (1903)
it fails with this error:
could not resolve property:PipelineId of :BP.IST.Domain.Trade.TradeLeg
This is because PipelineId element exists on PhysicalTradeLeg, not TradeLeg. But why does nhibernate use TradeLeg when "t.TradeLegs" is mapped to PhysicalTradeLeg?
(when PipelineId is not reference in the HQL, the PhysicalTrade is retrieved correctly with the bag of PhysicalTradeLegs... so mappings are correct)
Here are class snippets:
public class Trade : BaseBusinessObject {
private IList tradeLegs;
[XmlElement(Type = typeof(TradeLeg))]
public IList TradeLegs{
get{return tradeLegs;}
set{tradeLegs = value;}
}
....
....
}
public class TradeLeg : BaseBusinessObject {
....
....
}
public class PhysicalTrade : Trade {
....
....
}
public class PhysicalTradeLeg : TradeLeg {
private FacilityId pipeline;
public FacilityId Pipeline{
get{return pipeline;}
set{pipeline = value;}
}
....
....
}
Here are mapping snippets:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BP.IST.Domain.Trade.Trade,BP.IST.Domain" table="Trade">
<jcs-cache usage="read-write"/>
<id name="Id" column="Trade_key" type="long">
<generator class="sequence">
<param name="sequence">Trade_Seq</param>
</generator>
</id>
<discriminator column="Trade_Type_Cd_Key" />
<bag name="TradeLegs" lazy="false" cascade="all" inverse="true">
<key column="Trade_Key"/>
<one-to-many class="BP.IST.Domain.Trade.TradeLeg,BP.IST.Domain"/>
</bag>
....
....
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BP.IST.Domain.Trade.TradeLeg,BP.IST.Domain" table="Trade_Leg">
<jcs-cache usage="read-write"/>
<id name="Id" column="Trade_Leg_Key" type="long">
<generator class="sequence">
<param name="sequence">Trade_Leg_Seq</param>
</generator>
</id>
....
....
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<subclass name="BP.IST.Domain.Trade.PhysicalTrade,BP.IST.Domain" extends="BP.IST.Domain.Trade.Trade,BP.IST.Domain"
discriminator-value="39">
<bag name="TradeLegs" lazy="false" cascade="all" inverse="true">
<key column="Trade_Key"/>
<one-to-many class="BP.IST.Domain.Trade.PhysicalTradeLeg,BP.IST.Domain"/>
</bag>
....
....
</subclass>
</hibernate-mapping>
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<joined-subclass name="BP.IST.Domain.Trade.PhysicalTradeLeg,BP.IST.Domain" extends="BP.IST.Domain.Trade.TradeLeg,BP.IST.Domain" table="PHY_TRADE_LEG_VW">
<key column="Trade_Leg_Key" />
<component name="Pipeline" class="BP.IST.Domain.Facility.FacilityId,BP.IST.Domain" insert="false" update="false">
<property name="Id" column="Pipeline_Id" />
<component name="Name" class="BP.IST.Domain.Name,BP.IST.Domain">
<property name="FullName" column="Pipeline_Name"/>
</component>
</component>
....
....
</joined-subclass>
</hibernate-mapping>
|