-->
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: Unable to load type from assembly
PostPosted: Mon Apr 24, 2006 12:17 pm 
Newbie

Joined: Mon Apr 24, 2006 12:05 pm
Posts: 5
Location: Minnesota
I have a class library that houses my domain classes. I have a separate class library that houses the NHibernate specific classes for handling the data access... it is in this assembly that my mapping files are placed. When I call to build the session factory I am getting an exception thrown when NHibernate attempts to load the "Participant" class from the domain class assembly. The exception shows that NHibernate is attempting to load this class from the NHibernate assembly and not the domain class assembly.

Exception Message: "Could not load type 'Lighthouse1.LH1OnDemand.Members.Participant, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null', check that type and assembly names are correct"

The type should be loaded from "Lighthouse1.LH1OnDemand.Members.Participant, LH1OnDemand.Domain.Core"

My mapping file is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<import class="Lighthouse1.LH1OnDemand.Members.Participant, LH1OnDemand.Domain.Core" />
<class name="Participant" table="Individual">
<id name="IndividualId" column="ind_id" type="Int32">
<generator class="identity" />
</id>
<property name="FirstName" column="first_name" type="String" />
<property name="MiddleName" column="middle_name" type="String" />
<property name="LastName" column="last_name" type="String" />
<property name="BirthDate" column="birth_dt" type="Date" />
<property name="SocialSecurityNumber" column="ssn" type="String" />
<property name="MotherMaidenName" column="mother_maiden_name" type="String" />
<property name="EmailAddress" column="email_addr" type="String" />
<property name="Gender" column="gender" type="Lighthouse1.LH1OnDemand.Members.Gender" />
<property name="MaritalStatus" column="marital_status" type="Lighthouse1.LH1OnDemand.Members.MaritalStatus" />
<one-to-one
name="Employment"
class="Employment"
cascade="all"
fetch="join" />
</class>
</hibernate-mapping>

I have tried the class name as just Participant and also as the fully qualified name with namespace and assembly.

Have I incorrectly done the import process or do I have to add additional configuration to allow NHibernate to access the correct assembly?

Hibernate version: 1.0.2
Database: MS SQL 2005 (with 2000 dialect)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 1:42 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Why <import> the type *and* declare the same type in a <class> mapping? I've never seen that before - can't say if that would cause the problem, but it jumped out at me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 2:05 pm 
Newbie

Joined: Mon Apr 24, 2006 12:05 pm
Posts: 5
Location: Minnesota
How do I go about handling the situation where the *.hbm.xml files are in one dll and the implementing class is another dll? When it goes to look at the mapping file I want it to load the type from the domain class library (LH1OnDemand.Domain.Core) and not the NHibernate dll.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 4:36 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Use assembly-qualified class name:
Code:
<class name="Lighthouse1.LH1OnDemand.Members.Participant, LH1OnDemand.Domain.Core">
    ...
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 5:12 pm 
Newbie

Joined: Mon Apr 24, 2006 12:05 pm
Posts: 5
Location: Minnesota
Here is my mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="false">
<class name="Lighthouse1.LH1OnDemand.Members.Participant, LH1OnDemand.Domain.Core" table="Individual">
<id name="IndividualId" column="ind_id" type="Int32">
<generator class="identity" />
</id>
<property name="FirstName" column="first_name" type="String" />
<property name="MiddleName" column="middle_name" type="String" />
<property name="LastName" column="last_name" type="String" />
<property name="BirthDate" column="birth_dt" type="Date" />
<property name="SocialSecurityNumber" column="ssn" type="String" />
<property name="MotherMaidenName" column="mother_maiden_name" type="String" />
<property name="EmailAddress" column="email_addr" type="String" />
<one-to-one
name="Employment"
class="Employment"
cascade="all"
fetch="join" />
</class>
</hibernate-mapping>

Here is my NHibernate configuration:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<!-- an ISessionFactory instance -->
<session-factory>
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=dbserver;Database=dbname;User ID=user;Password=pswd</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="use_outer_join">true</property>
<!-- mapping files -->
<mapping assembly="LH1OnDemand.Data.NHibernate" />
<mapping assembly="LH1OnDemand.Domain.Core" />
</session-factory>
</hibernate-configuration>

My dll setup is as follows:

LH1OnDemand.Data.NHibernate
- Contains Participant.hbm.xml
- Contains implementation of ParticipantRepository (NHibernateParticipantRepository.cs)

LH1OnDemand.Domain.Core
- Contains Participant class (Lighthouse1.LH1OnDemand.Members.Participant)
- Contains abstract repository ParticipantRepository.
- Contains RepositoryLocator<> which is responsible for instantiating the correct repository implementation based on a config file.

TestHarness.exe
- Test console app with a reference to LH1OnDemand.Core
- Config file with a reference to the LH1OnDemand.Data.NHibernate assembly. This is used to create an instance of NHibernateParticipantRepository at run-time.


In TestHarness.Program.Main:

ParticipantRepository repository = RepositoryLocator<ParticipantRepository>.GetRepository();
Participant participant = repository.FindParticipant(admins[id], emps[id], id);

In LH1OnDemand.Domain.Core.RepositoryLocator<>:

public static TRepository GetRepository()
{
Type t = typeof(TRepository);
string name = t.FullName;

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
RepositoryConfiguration repositoryConfig = (RepositoryConfiguration)config.GetSection("lh1Repository");
RepositoryConfigurationElement trepositoryConfig = repositoryConfig.RepositoryList[name];

Type trepositoryType = Type.GetType(trepositoryConfig.Type);
return (TRepository)Activator.CreateInstance(trepositoryType);
}

The above works successfully and I then debug into NHibernateParticipantRepository:

public override Participant FindParticipant(string admin, string employer, int indId)
{
Participant participant = null;

Configuration config = new Configuration();
config.Configure();

ISessionFactory factory = config.BuildSessionFactory();
ISession session = factory.OpenSession();
try
{
participant = (Participant)session.Load(typeof(Participant), indId);
}
catch (Exception)
{
throw;
}
finally
{
session.Close();
}
return participant;
}

Now, I realize that I'm not supposed to build a session factory every time... this is just some test code to get things working. But when it makes the call to config.Configure() I get the following exception:

"Could not load type 'Lighthouse1.LH1OnDemand.Members.Participant, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null', check that type and assembly names are correct"

What I don't understand is why it is looking in the NHibernate assembly when the mapping clearly states that it should go to the Domain.Core assembly for the class definition.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 4:00 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
wrohrbach wrote:
What I don't understand is why it is looking in the NHibernate assembly when the mapping clearly states that it should go to the Domain.Core assembly for the class definition.


The mapping you showed was correct, but maybe the mapping file isn't actually the one that gets loaded. Check that NH really loads this mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 10:05 am 
Newbie

Joined: Mon Apr 24, 2006 12:05 pm
Posts: 5
Location: Minnesota
Here is the log output I receive:

INFO [2388] (:0) - Using dialect: NHibernate.Dialect.MsSql2000Dialect
INFO [2388] (:0) - Mapping class: Lighthouse1.LH1OnDemand.Members.Employment ->
Participant
ERROR [2388] (:0) - Could not compile the mapping document
NHibernate.MappingException: could not find class: Participant ---> System.TypeL
oadException: Could not load type 'Participant, NHibernate, Version=1.0.2.0, Cul
ture=neutral, PublicKeyToken=null', check that type and assembly names are corre
ct
at NHibernate.Util.ReflectHelper.ClassForName(String name)
at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String erro
rMessage)
--- End of inner exception stack trace ---
at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String erro
rMessage)
at NHibernate.Cfg.Binder.ClassForNameChecked(String name, Mappings mappings,
String errorMessage)
at NHibernate.Cfg.Binder.BindOneToOne(XmlNode node, OneToOne model, Boolean i
sNullable, Mappings mappings)
at NHibernate.Cfg.Binder.PropertiesFromXML(XmlNode node, PersistentClass mode
l, Mappings mappings)
at NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mapping
s mappings)
at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc)

The above makes me believe the problem may be in how I mapped the relationship between Participant and Employment.

Participant Mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Lighthouse1.LH1OnDemand.Members.Participant, LH1OnDemand.Domain.Core" table="Individual">
<id name="IndividualId" column="ind_id" type="Int32">
<generator class="identity" />
</id>
<property name="FirstName" column="first_name" type="String" />
<property name="MiddleName" column="middle_name" type="String" />
<property name="LastName" column="last_name" type="String" />
<property name="BirthDate" column="birth_dt" type="Date" />
<property name="SocialSecurityNumber" column="ssn" type="String" />
<property name="MotherMaidenName" column="mother_maiden_name" type="String" />
<property name="EmailAddress" column="email_addr" type="String" />
<one-to-one
name="Employment"
class="Employment"/>
</class>
</hibernate-mapping>

Employment Mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Lighthouse1.LH1OnDemand.Members.Employment,LH1OnDemand.Domain.Core" table="Participant">
<id name="IndividualId" column="ind_id">
<generator class="foreign">
<param name="property">Participant</param>
</generator>
</id>
<property name="EmployeeNumber" column="employee_nbr" type="String" />
<property name="WorkHoursPerWeek" column="hours_per_week" type="Int32" />
<property name="Salary" column="salary" type="Decimal" />
<property name="HireDate" column="hire_dt" type="Date" />
<one-to-one
name="Participant"
class="Participant"
constrained="true" />
<many-to-one
name="Employer"
column="employer_id"
class="Employer" />
</class>
</hibernate-mapping>

Employer Mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Lighthouse1.LH1OnDemand.Employers.Employer,LH1OnDemand.Domain.Core" table="Employer">
<id name="EmployerId" column="employer_id" type="Int32">
<generator class="identity" />
</id>
<property name="Alias" column="alias" type="String" />
<property name="Name" column="name" type="String" />
<property name="EmployerIdentificationNumber" column="ein" type="String" />
<property name="Url" column="url" type="String" />
<property name="ServiceEmail" column="service_email" type="String" />
</class>
</hibernate-mapping>

The debug output looks like it is having a problem when it attempts to resolve the relationship from Employment to Participant. The Participant is the parent in this relationship and passes IndividualId (ind_id) on to the child which is the Employment. Have I configured this relationship incorrectly? I modeled after the documentation under the one-to-one mapping description.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 10:11 am 
Newbie

Joined: Mon Apr 24, 2006 12:05 pm
Posts: 5
Location: Minnesota
I've got it now! It would help if I included the assembly in the hibernate-mapping element. I added assembly="LH1OnDemand.Domain.Core" and everything works great now. Thanks for everyone helping me out.


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.