-->
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.  [ 8 posts ] 
Author Message
 Post subject: Abstract class loses connection with joinedsubclass
PostPosted: Thu Oct 26, 2006 5:02 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Got an Error when using different mappingfiles for joined-subclasses. I was wondering if this is a known error in NHibernate

Example:

Hibernate version: 1.0.2

Mapping documents:

Code:
<hibernate-mapping>
  <class name="Namespace.Common.AbstractClass, Namespace.Common" table="GeneralItem">

    <id name="GeneralItemId"  type="Int32" column="GeneralItemId" >
      <generator class="identity"/>
    </id>

    <property name="... />
    general properties...
   
    <joined-subclass name="Namespace.Common.A.ConcreteClassA, Namespace.Common.A" table="ItemsA" extends="Namespace.Common.AbstractClass, Namespace.Common">
      <key column="GeneralItemId" />
      ..concrete properties for A..
    </joined-subclass>

    <joined-subclass name="Namespace.Common.B.ConcreteClassB, Namespace.Common.B" table="ItemsB" extends="Namespace.Common.AbstractClass, Namespace.Common">
      <key column="GeneralItemId" />
      ..concrete properties for B..
    </joined-subclass>

  </class>

</hibernate-mapping>



Now this works when we want to instantiate Concrete classes A and B in code using the Abstractclass in the IList.Criteria.

However, if we put the <joined-subclass> in a separate mapping file, for example in namespace common.A and common.B and remove the joined-subclasses from this mapping file than the following error occurs in our code:
"Cannot instantiate abstract class"

When we change the sourcecode to read in the concrete-classes, records -are- read from the database, but this is not what we want: we want to refer to the abstract-classes in our code.

So it seems that putting joined-subclass mappingfiles in their own namespace causes the abstract class being not aware of the joined-subclasses. It seems NHibernate is not aware of the connection between the mappingfiles even though we mentioned the extends attribute!

What gives?

Anybody noticed this before? Is this a known bug in NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:25 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You are probably not adding the mapping files correctly. Check DEBUG logs, you should see which classes NHibernate knows about when the session factory is created.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:46 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Hello Sergey. We have checked that: the mapping files are embedded and correctly read into the session.

The thing is that it breaks in sourcecode: but only if we put the joined-subclass in a separate hibernatemappingfile AND use the abstractclass.

We are sure the mappingfiles are correctly loaded, because if we change the sourcecode to use the concreteclass, records are read in from the database. Note: we really think we found a bug in NHibernate.

While basicly it should not matter how our code looks like, right?

example:


Code:
List<....> IRepository.GetItems(List<int> offerItemIds)
{
   List<AbstractClass> itemList = new List<AbstractClass>();
   ISession session = OurSession.CurrentSession;
   ICriteria NHibernateCriteria = session.CreateCriteria(typeof(AbstractClass));
   NHibernateCriteria.Add(Expression.In("GeneralItemId", generalItemIds.ToArray()));
   try
   {
     IEnumerable<AbstractClass> enumerable = (AbstractClass[])ArrayList.Adapter(NHibernateCriteria.List()).ToArray(typeof(AbstractClass));
     itemList = new List<AbstractClass>(enumerable);
   }
   catch(Exception exception)
   {
      ... log exception..
   }
......
  dostuff
  foreach(ConcreteClassA in itemList)
....
  return itemList
}


Let me try to explain what we found out:

In code above, it is possible to change all references AbstractClass to ConcreteClassA.

If we have one mappingfile, we can use AbstractClass.
If we put the joined-subclass in a separate mappingfile, the code with AbstractClass breaks with the mentioned error (cannot instantiate abstractclass) while if we change the code to use the ConcreteClassA, it works in both ways (using one mapping file or putting the joined-subclass(es) in their own mappingfiles).

..
Also: we know the separate joined-subclass mapping files are read because otherwise we get the error about the 'extends' class not known: so all mappingfiles must be read in order.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:40 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Can you create a simple example to reproduce it and submit to JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 7:43 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Yes... will do that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 8:31 pm 
Newbie

Joined: Thu Oct 26, 2006 2:49 pm
Posts: 11
Sorry, responded to wrong thread, tough day...


Last edited by djroberts@cox.net on Thu Oct 26, 2006 8:54 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 8:40 pm 
Newbie

Joined: Thu Oct 26, 2006 2:49 pm
Posts: 11
Disregard.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 5:48 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
added to jira as http://jira.nhibernate.org/browse/NH-779


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