-->
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.  [ 10 posts ] 
Author Message
 Post subject: Using derived classes in separate assemblys fails for me
PostPosted: Wed Jan 09, 2008 10:30 am 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
Hi i've got the following issue when developing with NHibernate;
I've got a couple of classes that derive from each other.
The mapping and access via SessionFactory.CreateSession works perfectly.
However if i seperate some of the Classes to a library assembly
(they are supposed to be loaded as a module) the call to
BuildSessionFactory throws the MappingException as below.

there's a method
[code]
Stream GetSerializerStream(Assembly assembly)
{
MemoryStream stream = new MemoryStream();
HbmSerializer.Default.Validate = true;
HbmSerializer.Default.Serialize(stream, assembly);
return stream;
}
[code]

Then when doing the following:
[code]
Configuration cfg = new Configuration();
cfg.Configure();

stream = GetSerializerStream(Assembly.GetExecutingAssembly());
cfg.AddInputStream(stream);
stream.Close();

stream = GetSerializerStream(Assembly.LoadFile(@"c:\Library.dll");
cfg.AddInputStream(stream);
stream.Close();

cfg.BuildSessionFactory();
[/code]
The exception is thrown when calling BuildSessionFactory. If all classes to be used by the OR/M are in the same assembly everything works.

I use a simple JoinedSubClass Mapping like this:
[code]
[NHibernate.Mapping.Attributes.Class(
Polymorphism = NHibernate.Mapping.Attributes.PolymorphismType.Implicit,
OptimisticLock= NHibernate.Mapping.Attributes.OptimisticLockMode.Version
)]
public class BaseClass
{
...
}

This is the derived class in the separate assembly:
[JoinedSubclass(Extends = "Namespace.BaseClass, MyExecutingAssembly")]
[Key(Column = "Id")]
public class DerivedClass : BaseClass
{
...
}
[/code]

Any help is greatly appreciated. And thanks for the great library!

Best regards,
Klaus


Hibernate version: 1.2.1.4000
Mapping documents: Are generated by NHibernate.Mapping.Attributes
Code between sessionFactory.openSession() and session.close():
not relevant

Full stack trace of any exception that occurs:
bei NHibernate.Cfg.MappingsQueue.CheckNoUnavailableEntries()
bei NHibernate.Cfg.Configuration.SecondPassCompile()
bei NHibernate.Cfg.Configuration.BuildSessionFactory()

Error message:
These classes referenced by 'extends' were not found:
<
classes *not* in the separated library but of the executing assembly,
exactly those are not found which are extended in the separated lib
>

Name and version of the database you are using:
Ms Sql but not relevant

The generated SQL (show_sql=true):
not relevant as well


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 10:59 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
After each call to AddInputStream try to inspect or print the Configuration class ClassMappings collection to see if it contains the items

PS: The documentation states that you need not to use a memory stream take a look at chapter 22.1 bulletpoint number 4 :-)


Top
 Profile  
 
 Post subject: the classes of the library are not found in the classmapping
PostPosted: Wed Jan 09, 2008 11:36 am 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
jta wrote:
After each call to AddInputStream try to inspect or print the Configuration class ClassMappings collection to see if it contains the items

the classes of the library assembly are not added to
cfg.ClassMappings.

However I inspected the output of the HbmSerializer MemoryStream which
clearly contains all the xml-mappings that are to be expected in the library assembly.

It seems to me, that cfg.AddInputStream does not handle them somehow

jta wrote:
PS: The documentation states that you need not to use a memory stream take a look at chapter 22.1 bulletpoint number 4 :-)

thanks for the hint, i use
Code:
     Assembly libAsm = Assembly.LoadFile(@"c:\Library.dll");
     stream = HbmSerializer.Default.Serialize(libAsm);
     cfg.AddInputStream(stream);

now, which keeps things more readable.

regards, klaus


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 11:41 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
AddInputStream works apperantly or else you would get errors for both the classes in ExecutingAssembly and the ones in your library, correct?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 11:46 am 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
jta wrote:
AddInputStream works apperantly or else you would get errors for both the classes in ExecutingAssembly and the ones in your library, correct?

Yes,
i call AddInputStream twice, first time with the HbmSerializer stream for the ExecutingAssembly which works, the ClassMappings of those classes are there, i printed them out.
after that i directly call it with the HbmSerializer stream from the freshly loaded Library.dll
The stream contains the correct XmlMapping Code (verified). AddInputStream does not throw any exception,
however the classmappings to not change.

which is why i get a MappingException when calling BuildSessionFactory


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 11:55 am 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
It seems a little strange, can you try to do something like this:
Code:
HbmSerializer.Default.Serialize(Assembly.LoadFile(@"c:\Library.dll"), "Library.hbm.xml");
HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly(), "Executing.hbm.xml");

cfg.AddFile("Library.hbm.xml");
cfg.AddFile("Executing.hbm.xml");


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:12 pm 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
Hello again, thanks for your assistance!

I've tried the code you provided. Interestingly enough the ClassMapping
stays empty if I first load the library.

i also tried it the other way around (first adding the mapping of the Executing assembly).

anyway, the generated mapping files are both correct and contain the right
references to the assemblies.

There is a subtle thing i noticed in the MappingException when BuildSessionFactory is called:

it states
These classes referenced by 'extends' were not found:
ClassA, MyExecutingAssembly
ClassB, MyExecutingAssembly
ClassC, MyExecutingAssembly

however ClassC is definitely in the Library Assembly!

regards Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:21 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
I haven't used Mapping.Attributes very much, but can't you specify a fully qualified name including assembly for your types?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 1:10 pm 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
Yes thats what i did,

as stated in the first post
Code:
[JoinedSubclass(Extends = "Namespace.BaseClass, MyExecutingAssembly")]
[Key(Column = "Id")]

The baseclass is specified with the Fullname and the Assembly it resides in.
Mapping.Attributes then generates the hbm.xml files and adds
the Fullname and Assembly of the subclass which is retrieved reflectively.
I checked them as well in
Code:
HbmSerializer.Default.Serialize(Assembly.LoadFile(@"c:\Library.dll"), "Library.hbm.xml");

they are correct alltogether.

Maybe it has something todo with the location of the assembly since i lazily copied it to c: in order to simulate the module behaviour

My proposal, i'll create a test project which reproduces the behaviour and post it somewhere on the net
- will check for myself by debugging it and try to find out what is happening. i currently only use the binary nhibernate dll

thanks, regards Klaus


Top
 Profile  
 
 Post subject: working example with Mapping.Attributes support
PostPosted: Wed Jan 09, 2008 4:01 pm 
Newbie

Joined: Wed Jan 09, 2008 9:31 am
Posts: 8
jta wrote:
I haven't used Mapping.Attributes very much, but can't you specify a fully qualified name including assembly for your types?

hi jta,
issue is solved it.
a project was built up from scratch and it worked. actually it is necessary to place the library.dll file next to the compiled executable. that strange behaviour described above did not show up however, need to investigate that tomorrow, this time everything went smooth.
if anybody is interested in the project, i set up a complete working example
download here: http://hostfil.es/file/8781/NHibernateIssue-zip.html
(sorry for the commercials displayed) additionally the mysql driver is required (or the nhibernate.cfg.xml needs to be changed to fit your particular needs)

regards klaus


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