-->
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.  [ 6 posts ] 
Author Message
 Post subject: Wrong mapping file used in List() by NH1.0
PostPosted: Thu Oct 13, 2005 3:15 pm 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
The case is following.

I have a value object named CigEntity, which has 2 subclasses - CigEntityIndividual and CigEntityCompany, that maps to a table name c_ge_CigEntity

In other namespace there is a value object named CigEntityDP, that inherits from CigEntity, which has 2 subclasses - CigEntityIndividualDP and CigEntityCompanyDP. Both these subclasses has mapping file pointing to the table c_dp_CigEntity.

It seems that when loading value object CigEntity -> from table c_ge_CigEntity with List, the table c_dp_CigEntity is used in the sql instead of c_ge_CigEntity. It works fine with Load.

I tried to discard the mapping file for CigEntityIndividualDP and CigEntityCompanyDP from the dll and then all worked fine.

This problem is only in RC1 and newer - not in the beta.

Here is mapping for CigEntityIndividualDP
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.DP.General.CigEntityIndividualDP, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
<id name="CreditinfoId" column="CreditinfoId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<!--<discriminator column="Type" type="Int32"/>-->
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="Type" column="Type"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Inserted" column="Inserted" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="InsertedBy" column="InsertedBy"/>
<property name="Updated" column="Updated" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="UpdatedBy" column="UpdatedBy"/>
<property name="Disabled" column="Disabled" type="Boolean"/>
</class>
</hibernate-mapping>


Here is mapping for CigEntityCompanyDP
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.DP.General.CigEntityCompanyDP, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
<id name="CreditinfoId" column="CreditinfoId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<!--<discriminator column="Type" type="Int32"/>-->
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="Type" column="Type"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Inserted" column="Inserted" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="InsertedBy" column="InsertedBy"/>
<property name="Updated" column="Updated" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="UpdatedBy" column="UpdatedBy"/>
<property name="Disabled" column="Disabled" type="Boolean"/>
</class>
</hibernate-mapping>


Any suggestions?

Regards,
Haukur


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 4:11 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please post the code that causes the problem, I don't quite understand what you are doing. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 8:21 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
And can you give more details about the hierarchy of CigEntity?
(which one are mapped as <class> / <subclass>?)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 6:23 am 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
Hi

Here are classes and mapping for CigEntity and CigEntityDP


----- CigEntity -----


Code:
using System;
using System.Collections;
using System.Xml.Serialization;

using CigFramework.ValueObject.Base;
using ValueObjects.General.Address;
using ValueObjects.General.Company;
using ValueObjects.General.Identification;
using ValueObjects.General.Individual;
using ValueObjects.General.Phone;

namespace ValueObjects.General
{
   /// <summary>
   /// Implementation of the ICigEntity interface.
   /// </summary>
   [Serializable]
   public class CigEntity
   {
      private bool isSearchable;
      private int providerId;
      private int originId;
      private int cId;
      private bool disabled;

      /// <summary>
      /// Default constructor.
      /// </summary>
      public CigEntity()
      {
      }

      /// <summary>
      /// Tells if the entity appears in search results
      /// </summary>
      public bool IsSearchable
      {
         get { return isSearchable; }
         set { isSearchable = value; }
      }

      /// <summary>
      /// Id of the subscriber that provided the information
      /// </summary>
      public int ProviderId
      {
         get { return providerId; }
         set { providerId = value; }
      }

      /// <summary>
      /// Id of the origin of the entity
      /// </summary>
      public int OriginId
      {
         get { return originId; }
         set { originId = value; }
      }



            /// <summary>
      /// The Creditinfo Id used to identify the object
      /// </summary>
      public int CId
      {
         get { return cId; }
         set { cId = value; }
      }

      /// <summary>
      /// Indicates wether the object is disabled or enabled.  If the object is disabled the value is true.
      /// </summary>
      public bool Disabled
      {
         get {return disabled; }
         set { disabled = value; }
      }
   }


   [Serializable]
   public class CigEntityIndividual : CigEntity
   {
      private IIndividual _individual;

      #region ICigEntityIndividual Members

      /// <summary>
      /// Get or sets an instance of Individual entity.
      /// </summary>
      public IIndividual Individual
      {
         get
         {
            return _individual;
         }
         set
         {
            _individual = value;
         }
      }

      #endregion
   }


   [Serializable]
   public class CigEntityCompany : CigEntity
   {
      private ICompany _company;

      #region ICigEntityCompany Members

      /// <summary>
      /// Gets or sets an instance of Company entity.
      /// </summary>
      public ICompany Company
      {
         get
         {
            return _company;
         }
         set
         {
            _company = value;
         }
      }

      #endregion
   }

}



---- CigEntity.hbm.xml ----

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="ValueObjects.General.CigEntity, ValueObjects" table="c_ge_CigEntity" discriminator-value="-99">
      <id name="CId" column="CId" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <discriminator column="Type" type="Int32"/>
      <property name="IsSearchable" column="IsSearchable" type="Boolean"/>
      <property name="ProviderId" column="ProviderId"/>
      <property name="OriginId" column="OriginId"/>
      <property name="Disabled" column="Disabled" type="Boolean"/>

      <subclass name="ValueObjects.General.CigEntityIndividual, ValueObjects" discriminator-value="1">
         <many-to-one name="Individual" class="ValueObjects.General.Individual.Individual, ValueObjects" column="CId" insert="false" update="false"/>
      </subclass>

      <subclass name="ValueObjects.General.CigEntityCompany, ValueObjects" discriminator-value="2">
         <many-to-one name="Company" class="ValueObjects.General.Company.Company, ValueObjects" column="CId" insert="false" update="false"/>
      </subclass>
   </class>
</hibernate-mapping>




---- CigEntityDP ----



Code:
using System;
using System.Collections;
using System.Xml.Serialization;

namespace ValueObjects.DP.General
{

   [Serializable]
   public class CigEntityDP : ValueObjects.General.CigEntity
   {
      private int type;

      /// <summary>
      /// The Id of the type
      /// </summary>
      public int Type
      {
         get { return type; }
         set { type = value; }
      }

   }


   [Serializable]
   public class CigEntityIndividualDP : CigEntityDP
   {
      private Individual.IIndividualDP individual;

      /// <summary>
      /// Default constructor - sets the type of CigEntity
      /// </summary>
      public CigEntityIndividualDP()
      {
         Type = 1;
      }

      /// <summary>
      /// The Individual
      /// </summary>
      public Individual.IIndividualDP Individual
      {
         get { return individual; }
         set { individual = value; }
      }
   }


   [Serializable]
   public class CigEntityCompanyDP : CigEntityDP
   {
      private Company.ICompanyDP company;

      /// <summary>
      /// Default constructor - sets the type of CigEntity
      /// </summary>
      public CigEntityCompanyDP()
      {
         Type = 2;
      }

      /// <summary>
      /// The Company
      /// </summary>
      public Company.ICompanyDP Company
      {
         get { return company; }
         set { company = value; }
      }

   }
}



---- CigEntityDP.hbm.xml ----

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="ValueObjects.DP.General.CigEntity, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
      <id name="CId" column="CId" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <discriminator column="Type" type="Int32"/>
      <property name="IsSearchable" column="IsSearchable" type="Boolean"/>
      <property name="ProviderId" column="ProviderId"/>
      <property name="OriginId" column="OriginId"/>
      <property name="Disabled" column="Disabled" type="Boolean"/>

      <subclass name="ValueObjects.DP.General.CigEntityIndividualDP, ValueObjects" discriminator-value="1">
         <many-to-one name="Individual" class="ValueObjects.DP.General.Individual.Individual, ValueObjects" column="CId" insert="false" update="false"/>
      </subclass>

      <subclass name="ValueObjects.DP.General.CigEntityCompanyDP, ValueObjects" discriminator-value="2">
         <many-to-one name="Company" class="ValueObjects.DP..General.Company.Company, ValueObjects" column="CId" insert="false" update="false"/>
      </subclass>
   </class>
</hibernate-mapping>



The code I used to load a list of CigEntity is the following


ICriteria criteria = session.CreateCriteria(CigEntity);
criteria.SetMaxResults(maxReadResults);
//Some other criteria
IList results = criteria.List();
return results;

If I look at the sql generated then the table c_dp_CigEntity is used instead if c_ge_CigEntity

If i remove the CigEntityDP.hbm.xml from the project then it works fine - also if I load a single CigEntity with Load

Regards,
Haukur


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:00 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
In the mapping of CigEntityDP.hbm.xml; you should write:
Code:
<class name="ValueObjects.DP.General.CigEntity[b]DP[/b], ValueObjects" [...]>

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 5:25 am 
Newbie

Joined: Mon Jun 20, 2005 7:30 am
Posts: 8
Hi

It was a mistake in the mapping file I posted - in my app it is mapped to CigEntityDP. So that was not the problem.

Code:
<class name="ValueObjects.DP.General.CigEntityDP, ValueObjects" [...]>


Regards,
Haukur


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.