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.  [ 1 post ] 
Author Message
 Post subject: Implicit polymorphism for many-to-one. Possible bug
PostPosted: Wed Apr 09, 2008 5:07 am 
Newbie

Joined: Tue Apr 08, 2008 11:27 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

NHibernate 1.2 -2.0

I have database(see image)

Image

Mapping documents:



Product
Code:
<class name="Product" table="Product">
      <id name="Id" column="Id" type="System.Int32">
         <generator class="increment"/>
      </id>      
      ...
</class>


Cons_Product
Code:
<joined-subclass name="Cons_Product" table="Cons_Product" extends="Product">
      <key column="Id"/>
      ...
   </joined-subclass>


PurchaseOrder
Code:
<joined-subclass name="PurchaseOrder" table="PurchaseOrder" extends="WorkflowItem">
      <key column="Id"/>
      <set name="PurchaseItems" lazy="true" inverse="true" cascade="all" table="PurchaseItem">
         <key column="PurchaseOrderId" />
         <one-to-many class="PurchaseItem" />
      </set>
      ...
   </joined-subclass>


Cons_PurchaseOrder
Code:
<joined-subclass name="Cons_PurchaseOrder" table="Cons_PurchaseOrder" extends="PurchaseOrder"  >
      <key column="Id"/>
      ...
   </joined-subclass>


PurchaseItem
Code:
<class name="PurchaseItem" table="PurchaseItem">

      <id name="Id" column="Id" type="System.Int32">
         <generator class="increment"/>
      </id>
      ...
      <many-to-one name="ProductIdObject" column="ProductId" not-null="true" />
   </class>


Cons_PurchaseItem
Code:
<joined-subclass name="Cons_PurchaseItem" table="Cons_PurchaseItem" extends="PurchaseItem">
      <key column="Id"/>
      ...
   </joined-subclass>



Name and version of the database you are using:
MSSQL 2005

Classes

PurchaseOrder
Code:
public class PurchaseOrder : WorkflowItem
    {

...
      private ISet<PurchaseItem> m_PurchaseItems = null;

      [XmlIgnore()]
      public virtual ISet<PurchaseItem> PurchaseItems
      {
         get
         {
            if (m_PurchaseItems == null)
               m_PurchaseItems = new HashedSet<PurchaseItem>();
            return m_PurchaseItems;
         }
         set { m_PurchaseItems = value; }
      }
    }


PurchaseItem
Code:
public class PurchaseItem
   {
...

      private Product _productIdObject = null;

      public virtual Product ProductIdObject
      {
         get { return _productIdObject; }
         set { _productIdObject = value; }
      }
   }



Problem

When I try to execute folowing code

Code:
Cons_PurchaseOrder purchaseOrder = (Cons_PurchaseOrder)_poBlo.GetEntityById(typeof(Cons_PurchaseOrder), 2);


in field PurchaseItems of returned purchaseOrder I have entities typeof Cons_PurchaseItem, but in ProductIdObject I have entity typeof Product.
NHibernate by default use Implicit polymorphism and I wait that typeof object in this field should be Cons_Product(like in case with field PurchaseItems).

SQL query for field ProductIdObject
Code:
SELECT product0_.Id as Id4_0_, product0_.Description as Descript2_4_0_, product0_.Price as Price4_0_, product0_.ProductName as ProductN4_4_0_, product0_.Units as Units4_0_, product0_.CategoryId as CategoryId4_0_, product0_1_.ImageName as ImageName10_0_, case when product0_1_.Id is not null then 1 when product0_.Id is not null then 0 end as clazz_0_ FROM Product product0_ left outer join Cons_Product product0_1_ on product0_.Id=product0_1_.Id WHERE product0_.Id=@p0; @p0 = '8'

In according to this query NHibernate should use Cons_Product as base in process of proxy generation. But it using class Product.

What should I do to get Cons_Product without setting attribute "class" to Cons_Product in mapping for PurchaseItem? Is it a bug?


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

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.