-->
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: AddAssembly doesn't seem to order joined-subclass correctly
PostPosted: Tue Mar 06, 2007 8:52 pm 
Newbie

Joined: Fri Jan 12, 2007 4:39 pm
Posts: 6
I am using AddAssembly(assembly) to add an assembly to NHibernate. The assembly contains objects that form the inheritance hierarchy as follow:

Item<--SellableItem<--PhysicalItem<--Asset

where Item is the base class.

I am not setting the skipOrder parameter so I expect Hibernate to order the mapping files according to the inheritance hierarchy.

The problem I am running into is that sometimes Hibernate doesn't seem to order the mapping files the way it is in the inheritance hierarchy and I get the following mapping exception:

Could not compile the mapping document: Platform.Asset.hbm.xml ---> NHibernate.MappingException: Could not compile the mapping document: Platform.Asset.hbm.xml ---> NHibernate.MappingException: Cannot extend unmapped class: Platform.PhysicalItem,A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll.

This seems to have something to do with the order of the mapping files read from the assembly resource because it happens if the order of the mapping file read from assembly by AddAssembly() is:

Asset
Sellable
PhysicalItem
Item

Does anyone have any idea what causes this and if there is a way to work around it?

Hibernate version:
1.2.0.beta3

Mapping documents:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Platform"
assembly="Platform"
default-cascade="save-update">

<joined-subclass name="Patform.Asset"
extends="Platform.PhysicalItem, Platform"
table="ASSET">

<key column="UNIQUE_ID" />

</joined-subclass>

</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Platform"
assembly="Platform"
default-cascade="save-update">

<joined-subclass name="Platform.PhysicalItem"
extends="Platform.SellableItem, Platform"
table="PHYSICALITEM">

<key column="UNIQUE_ID" />

</joined-subclass>

</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Platform"
assembly="Platform"
default-cascade="save-update">

<joined-subclass name="Platform.SellableItem"
extends="Platform.Item, Platform"
table="SELLABLEITEM">

<key column="UNIQUE_ID" />

</joined-subclass>

</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Platform"
assembly="Platform"
default-cascade="save-update">

<class name="Platform.Item" table="ITEM">

<id name="UniqueId" column="UNIQUE_ID" type="string"
<generator class="uuid"/>
</id>

<version name="Version" type="long" column="VERSION" unsaved-value="negative" />

</class>

</hibernate-mapping>
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 11:12 pm 
Newbie

Joined: Fri Jan 12, 2007 4:39 pm
Posts: 6
I think I found the cause of the problem. There seems to be a bug in the AssemblyHbmOrder.OrderHbmFiles() method. The bug requires at least a four-level of joined-subclass and a specific ordering of the hbm files to reproduce. Here are the steps to reproduce it.

Assume this is the inheritance hierarchy:

Item <-- SellableItem <-- PhysicalItem <-- Asset

Where Item is the base class.

If the order in which the hbm files are read from the assembly is:

Asset.hbm.xml
SellableItem.hbm.xml
PhysicalItem.hbm.xml
Item.hbm.xml

Here is what happens according to the ordering logic in the OrderHbmFiles() method:

1. Assert.hbm.xml is the first hbm file read. Since there is nothing in the sortedList so it is put into the sortedList.

2. SellableItem.hbm.xml is the 2nd file read. Since SellableItem inherits from Item, it neither inherits from Asset that is in sortedList, nor Asset inherits from it. So accordingly it is put at the end of sortedList, after Asset. This is the cause of the problem. SellableItem needs to be in front of Asset. However, the implementation prematurely assumes that SellableItem is not a dependent or dependee simply because there isn't any in sortedList at the time. That's premature because there are other hbm files that may depend on it that haven't been processed yet.

3. The remaining two files, PhysicalItem and Item end up at the right order in sortedList.

So, the order of the files that comes out of the method is:

Item.hbm.xml
Asset.hbm.xml
SellableItem.hbm.xml
PhysicalItem.hbm.xml


Since Asset inherits from PhysicalItem, I get a mapping exception about not able to extend from unmapped class PhysicalItem when Asset is being mapped.

Can someone take a look at this and confirm if this is a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 09, 2007 3:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, it does look like a bug. Can you create a test case and submit it to JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 11:20 am 
Newbie

Joined: Fri Jan 12, 2007 4:39 pm
Posts: 6
Sergey, thanks for looking at it.

Sorry for the late response. I will create a test case and submit it to JIRA.

I have another related question about the order of resources in assemblies.

Let say I have assemblies A and B. Inside assembly A there is a class called Y and inside assembly B there is a class called X. Let's assume Y inherits from X.

If I add both assemblies in random order, meaning A is sometimes added before B is, it seems to me that NHibernate doesn't order the class X before Y. It does order the class within one assembly, but it doesn't seem to order the classes that are in different assemblies.

The behavior is different on Java Hibernate. Hibernate does seem to order the resources across multiple Jars based on dependency.

Is this behavior on NHibernate expected? If it is, is there plan to migrate to the Java Hibernate behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 8:53 pm 
Newbie

Joined: Fri Jan 12, 2007 4:39 pm
Posts: 6
Appolgies for taking so long. I filed NH-952 for the above problem, with test unit test attached.

Can you respond to my question about dependency ordering with multiple assemblies? Is there a workaround?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 2:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I probably will change the code to work like Hibernate 3 to fix this bug. I'll try to make sure the multiple assemblies scenario works correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 11:48 am 
Newbie

Joined: Mon Apr 16, 2007 10:24 am
Posts: 5
When I take /Cfg/AssemblyHbmOrderer.cs revision 2661 and make some trivial adjustments to match the required interface (implement CreateWithResources) it works fine for me. But then again I don't know which great features I miss out on.


Top
 Profile  
 
 Post subject: Mapping more then one assembly
PostPosted: Mon Apr 23, 2007 9:09 am 
Beginner
Beginner

Joined: Tue Jan 02, 2007 5:53 pm
Posts: 42
Location: Bergen, Norway
Hi!

I also need this functionality. Right now I'm wondering what the way around this could be.

Here is the code from my LocalSessionFactoryObject implementation used by Spring.Net DI to extract the mappings from the domain model(s);

Code:
......
// Extract mappings...
            foreach (Assembly assembly in assemblies)
            {
                MemoryStream stream = new MemoryStream(); // Where the information will be written in
                HbmSerializer.Default.Serialize(stream, assembly);
                stream.Position = 0;
                config.AddInputStream(stream); // Send the Mapping information to NHibernate Configuration
                stream.Close();
            }
......


If there is some other way around getting NHibernate to understand mappings from one assembly to a type defined in the other assembly then I'm very interested in the solution.

_________________
Cheers,
Steinar.


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.