-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Why is Nhibernate not using my joined subclass?
PostPosted: Fri Dec 02, 2005 12:45 pm 
Newbie

Joined: Tue Oct 11, 2005 3:18 pm
Posts: 16
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>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 11:20 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate can't handle this kind of "covariant" list correctly. I think the PhysicalTrade.TradeLegs property is sort of ignored in the mapping. Can you only map the TradeLegs property for the PhysicalTrade subclass?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 12:25 pm 
Newbie

Joined: Tue Oct 11, 2005 3:18 pm
Posts: 16
Thanks for the suggestion... initial testing with that workaround was fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.