-->
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.  [ 5 posts ] 
Author Message
 Post subject: [newbie] one-to-many (parent-childeren) mapping problem
PostPosted: Sun Dec 25, 2005 7:49 pm 
Newbie

Joined: Sun Dec 25, 2005 7:04 pm
Posts: 2
NHibernate 1.0.5000.0
dbe: PostgreSQL
language: c#


Let's assume i've two classes: user and address.

In user user.hbm.xml mapping file i add below to make connection between classes
(1)
Code:
<set name="userAddresses">
            <key column="parent_id"/>
            <one-to-many class="address"/>
</set>


Now every time code reaches :

Code:
cfg.AddAssembly("myAssembly");


my app. throws NHibernate.MappingException which i do not understand:

Code:
NHibernate.MappingException: associated class not found: hydrosoft.address ---> System.TypeLoadException: Nie można załadować typu address z zestawu NHibernate, Version=1.0.1.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc.\r\n   at System.Type.GetType(String typeName, Boolean throwOnError)\r\n   at NHibernate.Util.ReflectHelper.ClassForName(String name)\r\n   at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String errorMessage)\r\n   --- Koniec śladu stosu wyjątków wewnętrznych ---\r\n   at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String errorMessage)\r\n   at NHibernate.Cfg.Binder.ClassForNameChecked(String name, Mappings mappings, String errorMessage)\r\n   at NHibernate.Cfg.Binder.BindOneToMany(XmlNode node, OneToMany model, Mappings mappings)\r\n   at NHibernate.Cfg.Binder.BindCollection(XmlNode node, Collection model, String className, String path, Mappings mappings)\r\n   at NHibernate.Cfg.CollectionTypeSet.Create(XmlNode node, String prefix, String path, PersistentClass owner, Mappings mappings)\r\n   at NHibernate.Cfg.Binder.PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings)\r\n   at NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings)\r\n   at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)\r\n   at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc)\r\n   at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader)\r\n   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)\r\n   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)\r\n   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)\r\n   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)\r\n   at ...


I don't know why it doesn't see the address class beacause i can use it (the address class) if i delete (1) code from user.hbm.xml.

Without the (1) code pass the
Code:
cfg.AddAssembly("myAssembly");


and i can add/modify/delete users and addresses easily.

Do you have any idea why it throws the exception ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 6:13 pm 
Newbie

Joined: Sun Dec 25, 2005 7:04 pm
Posts: 2
it seems that instead of :

Code:
<set name="userAddresses">
            <key column="parent_id"/>
            <one-to-many class="address"/>
</set>


it should be :

Code:
<set name="userAddresses">
            <key column="parent_id"/>
            <one-to-many class="namespace.address,myAssembly"/>
</set>


Someone could tell me why ? In other examples i've seen class def without assembly keyword. Is there any rule for it ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 4:03 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
There is a property 'Auto-Import' defined on the mapping file, that allows you to use the class-name directly. Atleast, that works on HQL, but I guess you can use it in the mapping files as well.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 6:55 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
TheShark wrote:
There is a property 'Auto-Import' defined on the mapping file, that allows you to use the class-name directly. Atleast, that works on HQL, but I guess you can use it in the mapping files as well.


No, you can't. To j23tom: you have to use the assembly name because that's how reflection works in .NET. If you don't specify the name, it attempts to load the type from the currently executing assembly, which happens to be NHibernate.dll.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 7:01 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
You can specify default assembly and namespace in the mapping

e.g.
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="myAssembly" namespace="myNamespace" >

_________________
michal


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