-->
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.  [ 7 posts ] 
Author Message
 Post subject: component class not found for composite-key class
PostPosted: Tue May 24, 2005 8:45 am 
Newbie

Joined: Tue May 24, 2005 8:30 am
Posts: 4
I am working with a legacy database that uses composite keys. I created a composite identifier class, OperationId, to use as the id for my Operation class. In OperationId, I implement ISerializable and override Equals and GetHashCode. My Operation.hbm.xml class (compiled as an embedded resource) is:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ClassTester.Operation, ClassTester" table="OPERTN_NM_REF">
<composite-id name="Id" class="ClassTester.OperationId">
<key-property name="OperationCode" column="OPERTN_CD" />
<key-property name="OperationCategory" column="OPERTN_CAT_REF_CD" />
</composite-id>
<property name="DeleteIndicator" column="DLT_IND" type="Char" length="1"/>
<property name="OperationName" column="OPERTN_NM" type="String" length="50" />
<property name="OperationMessage" column="OPERTN_MSG_TXT" type="String" length="100" />
<property name="OperationDescription" column="OPERTN_DSC_TXT" type="String" length="200" />
</class>
</hibernate-mapping>

I have verified that the OperationId class is in my assembly (ClassTester).

When I execute
cfg.AddAssembly( "ClassTester" );
--OR--
cfg.AddClass( typeof( Operation ) );

I get the following exception:
Unhandled Exception: NHibernate.MappingException: component class not found --->
System.TypeLoadException: Could not load type ClassTester.OperationId
from assembly NHibernate, Version=0.8.3.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc.
at System.Type.GetType(String typeName, Boolean throwOnError)

at NHibernate.Cfg.Binder.BindComponent(XmlNode node, Component model,
Type reflectedClass, String className, String path, Boolean isNullable, Mappings mappings)


The way I read the exception, NHibernate is looking in the NHibernate assembly for my class instead of in my assembly

Where am I going wrong?

Thanks,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 9:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You have to use fully qualified name, just as you did in <class name="...">. By the way, if you specify assembly and namespace in the <hibernate-mapping> element, you won't need to qualify the class names in the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 9:25 am 
Newbie

Joined: Tue May 24, 2005 8:30 am
Posts: 4
Thank you for the quick reply, Sergey.

I tried:
cfg.AddClass( typeof( ClassTester.Operation ) );

and got the same result. Is this what you meant?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 10:00 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Sorry, I meant you have to use fully qualified name in the mapping, in the <composite-id> tag.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 12:00 pm 
Newbie

Joined: Tue May 24, 2005 8:30 am
Posts: 4
Here is my <composite-id> tag:
<composite-id name="Id" class="ClassTester.OperationId">
<key-property name="OperationCode" column="OPERTN_CD" />
<key-property name="OperationCategory" column="OPERTN_CAT_REF_CD" />
</composite-id>

The class attribute is fully qualified. Am I missing an attribute or element?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 1:42 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, you're missing the assembly name in the class attribute. It should be class="ClassTester.OperationId, ClassTester". If there's no assembly, .NET assumes the executing assembly which is NHibernate.dll, that's why it attempts to load the type from there.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 1:51 pm 
Newbie

Joined: Tue May 24, 2005 8:30 am
Posts: 4
Thank you, Sergey. Now I'm rolling.


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