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.  [ 13 posts ] 
Author Message
 Post subject: error while loading assembly
PostPosted: Fri Sep 22, 2006 6:20 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Hi Group,

I have created business entity project with the project name as "HospitalMgmt" and inside it I have created folder "BusinessEntities" which contains classes for business entities and namespace used is "HospitalMgmt.BusinessEntities". Assembly name is "HospitalMgmt.dll".

Code snippet is as below:

Configuration config = new Configuration();
config.AddAssembly(System.Reflection.Assembly.LoadFrom(@"HospitalMgmt.dll"));

Error is :

expn.Message = "persistent class HospitalMgmt.BusinessEntities.PatientDoctor, HospitalMgmt.BusinessEntities not found"

I have gone through the source code of nHibernate 1.2.0 ALpha1 and i found the following mistake.
1. In NHibernate.Util.ReflectHelper Class, functoin public static System.Type TypeFromAssembly( AssemblyQualifiedTypeName name ) contains a call to method Assembly.Load(name.Assembly) method.
When I debug the application and go to the Assembly.Load call, name.Assembly contains "HospitalMgmt.BusinessEntities". I think it should contain "HospitalMgmt" assembly name so that application can add the assembly.

Possible Workaround: In my case, assembly name is HospitalMgmt.dll
and namespace for business entity is "HospitalMgmt.BusinessEntities".
Now nhibernate tool tries to load the assembly with the name "HospitalMgmt.BusinessEntities" but actual asssembly name is "HospitalMgmt". NHibernate team has to make changes into existing code implimentation so that whatever namespace we have defined for business entity, it should load the assembly with the assembly name.


Top
 Profile  
 
 Post subject: Re: error while loading assembly
PostPosted: Fri Sep 22, 2006 7:08 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Can we see your mapping? Are you sure you dont't enter HospitalMgmt.BusinessEntities as assembly name yourself?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 8:17 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Take a look into file name and let me know if u want any more details:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="HospitalMgmt.BusinessEntities.PatientDoctor,HospitalMgmt.BusinessEntities" table="Patient_Doctor" lazy="true">

<composite-id access="field">
<key-property name="PatientId" column="Patient_Id" type="Int32" />
<key-property name="DoctorId" column="Doctor_Id" type="Int32" />

</composite-id>
<!-- Composite primary key is experimental. View the documentation for syntax. --><!-- problems: gustavohe@gmail.com -->
<many-to-one name="DiseaseId" column="Disease_Id" class="HospitalMgmt.BusinessEntities.Disease,HospitalMgmt.BusinessEntities" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 8:20 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
deepakbadki wrote:
<class name="HospitalMgmt.BusinessEntities.PatientDoctor,HospitalMgmt.BusinessEntities"


Should probably be be <class name="HospitalMgmt.BusinessEntities.PatientDoctor,HospitalMgmt"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 8:28 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
I have already tried that option. It seems like a bug in NHibernate because when i gone thru the code, extraction of assembly name uses mapping file wherein they are using the namespace value. But in my case namespace value is "HospitalMgmt.BusinessEntities" while assembly is "HospitalMgmt.dll".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 11:21 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
deepakbadki wrote:
I have already tried that option. It seems like a bug in NHibernate because when i gone thru the code, extraction of assembly name uses mapping file wherein they are using the namespace value. But in my case namespace value is "HospitalMgmt.BusinessEntities" while assembly is "HospitalMgmt.dll".


Aren't You mixing together assembly OS file name and assembly name? They are diffrent values....

Assembly name does not usually contain ".dll" suffix.

In type name, "Namespace.Name.PatientDoctor,Assembly.Name",

so, in case of "HospitalMgmt.BusinessEntities.PatientDoctor,HospitalMgmt.BusinessEntities", assembly name is "HospitalMgmt.BusinessEntities" (which is in this case same as namespace name)

Note that the assmbly OS file name is not part of the type name.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 1:03 pm 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Hi Gert,

I dont think so because assembly is the collection of all the compiled classes + manifest. And here assembly name is "HospitalMgmt.dll" so i have to code it as

Assembly.LoadFrom("HospitalMgmt.dll");

But if we talked about naming conventions, i have used namespace as "HospitalMgmt.BusinessEntities.PatientDoctor". And wat I found is nHibernate tool tries to load the assembly which it gets by just deleting the classname from the namespace i.e. HospitalMgmt.BusinessEntities.

Correct me if I am wrong!

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 12:51 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
And wat I found is nHibernate tool tries to load the assembly which it gets by just deleting the classname from the namespace i.e. HospitalMgmt.BusinessEntities.

No, you found wrong. Also, try not to use LoadFrom as it loads assemblies into a different context and NHibernate will not be able to load types from them. Use Load.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 6:11 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Hi Surgey,

I have tried both the options i.e. load and loadform but still no luck :(
I have explained the problem in my previous mail. And I have already gone thru the source code. In brief, my assembly name is "HospitalMgmt" and namespace is "HospitalMgmt.BusinessEntities". To load the assebly, nhibernate retrieves the assembly string by deleting just business entity from the above string. Lets say, if we have HospitalMgmt.BusinessEntities.Doctor class, then nHibernate tries to retrieve the assembly by deleting class name( Doctor )and tries to load the assembly with name "HospitalMgmt.BusinessEntities". But in actual, assembly name is "HospitalMgmt" then it throws an exception.

Please reply me ASAP.

-Thanks
Deepak


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 10:35 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
deepakbadki wrote:
I have tried both the options i.e. load and loadform but still no luck :(
I have explained the problem in my previous mail. And I have already gone thru the source code. In brief, my assembly name is "HospitalMgmt" and namespace is "HospitalMgmt.BusinessEntities". To load the assebly, nhibernate retrieves the assembly string by deleting just business entity from the above string. Lets say, if we have HospitalMgmt.BusinessEntities.Doctor class, then nHibernate tries to retrieve the assembly by deleting class name( Doctor )and tries to load the assembly with name "HospitalMgmt.BusinessEntities". But in actual, assembly name is "HospitalMgmt" then it throws an exception.

Please reply me ASAP.


Take a moment and read http://msdn2.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx

So, ig Your assembly name is "HospitalMgmt", have class mapping like

<class name="HospitalMgmt.BusinessEntities.PatientDoctor, HospitalMgmt" table="Patient_Doctor" lazy="true">

not

<class name="HospitalMgmt.BusinessEntities.PatientDoctor,HospitalMgmt.BusinessEntities" table="Patient_Doctor" lazy="true">

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 11:19 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Hi Gert,

I have changed the className to

<class name="HospitalMgmt.BusinessEntities.PatientDoctor, HospitalMgmt" table="Patient_Doctor" lazy="true">

but still its not working.

Hey I found out the problem(but no the solution for the same:)
Internally, tool calls

public static System.Type TypeFromAssembly( AssemblyQualifiedTypeName name )
method of the ReflectHelper class and inside this method , it contains a code called

"Assembly assembly = Assembly.Load( name.Assembly );"

it throws an exception because it it trying to load the assebly with the name "HospitalMgmt.BusinessEntities". but here it should be like "HospitalMgmt".

Gert, if you have time then try to execute the scenerio which I am takling about and plse plse let me know ASAP.

-Thanks
Deepak


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 12:09 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
deepakbadki wrote:
Gert, if you have time then try to execute the scenerio which I am takling about and plse plse let me know ASAP.


I changed mu project to have this short form of assembly name - and it works.

Make sure that all mapping files do specify correct class names. And rebuild (not just "build") Your project after changing mapppings. And so on.

Or post compileable minimal test project which replicates the problems.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 7:52 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Last week, I was very busy so cudn't replied. Sorry for the same.

Finally pb solved :)
Problem was with mapping file. We are using Mygeneration Object Mapping 1.1 template to create business entities and it was creating wrong mapping files. While executing the template, it asks for the namespace and internally it adds the class entry in mapping file as "namespace.classname, classname". But in our case, assembly name is quit different.
Workaround: I have modified the template in order to solver our purpose.


-Thanks


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