-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with self refering data objects
PostPosted: Thu Mar 09, 2006 10:46 am 
Newbie

Joined: Thu Mar 09, 2006 10:33 am
Posts: 2
I've been fighting with this problem for a couple of days now, but I can't find the solution:

I have a table containing info about citizens - name, address etc, but also the id of each of the parents - who them selves of course are citizens too, and thus are in the same table.

My DTO looks something like this:

public class CitizenDTO
{
private int id;
private string name;
private CitizenDTO mother;
...

public CitizenDTO()
{
}

...

public CitizenDTO Mother
{
get { return mother;}
set {mother = value;}
}
}


and the corresponding hbm.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="GDCS.CivilRegister.Test.CitizenDTO, GDCS.CivilRegister" table="Citizen"
dynamic-update="true" lazy="true">
<id name="Id" column="ID">
<generator class="assigned" />
</id>
<property name="Name" type="string" column="name" not-null="true" />

<many-to-one
name="mother"
class="GDCS.CivilRegister.Test.CitizenDTO"
cascade="none"
outer-join="auto"
update="true"
insert="true"
foreign-key="mother_fk"
column="mothersid"
/>

</class>
</hibernate-mapping>

The problem is when I test it, I get the error message:
NHibernate.MappingException: could not find class: GDCS.CivilRegister.Test.CitizenDTO ---> System.TypeLoadException: Could not load type 'GDCS.CivilRegister.Test.CitizenDTO, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', check that type and assembly names are correct
at NHibernate.Util.ReflectHelper.ClassForName(String name)

but the moment I remove the self referencing parts (mother), It works perfectly, so I have a feeling there's something missing in my xml file? Can anybody help me with this?

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 11:31 am 
Newbie

Joined: Mon Mar 06, 2006 3:22 am
Posts: 3
Hi Cyanid,
Try appending the assemby name to the name of the many-to-one class. Just like the class name of your class itself.
So, instead of
[code]
<many-to-one
name="mother"
class="GDCS.CivilRegister.Test.CitizenDTO"
[/code]
use
[code]
<many-to-one
name="mother"
class="GDCS.CivilRegister.Test.CitizenDTO, GDCS.CivilRegister"
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 11:46 am 
Newbie

Joined: Thu Mar 09, 2006 10:33 am
Posts: 2
Thanks a lot! This really helped!

Now an error occurs in the next line of code instead. And I think I've still got problems with my hbm.xml file. Here's the code:

Configuration cfg = new Configuration();
cfg.AddAssembly("GDCS.CivilRegister");
_sessions = cfg.BuildSessionFactory();

ISession session = _sessions.OpenSession();
ICriteria citizen = session.CreateCriteria(typeof(CitizenDTO));
citizen.Add(Expression.Eq("Name", name));
citizen.Add(Expression.Eq("Mother.Name",mothersName));

IList list = citizen.List();

The error occures in the last line. The xml file is like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="GDCS.CivilRegister.Test.CitizenDTO, GDCS.CivilRegister" table="TestCitizen"
dynamic-update="true" lazy="true">
<id name="Id" column="ID">
<generator class="assigned" />
</id>
<property name="Name" type="string" column="name" not-null="true" />
<!-- mulige parametre:
update="true" insert="true" not-null="true"-->

...

<many-to-one
name="Mother"
class="GDCS.CivilRegister.Test.CitizenDTO, GDCS.CivilRegister"
cascade="none"
outer-join="auto"
update="true"
insert="true"
foreign-key="mother_fk"
column="mothersid"
/>

</class>
</hibernate-mapping>

and the error message this:

NHibernate.QueryException: could not resolve property:Mother.Name of :GDCS.CivilRegister.Test.CitizenDTO

The moment I delete the line
citizen.Add(Expression.Eq("Mother.Name",mothersName));

the program works fine and returns exactly what i expect.

Thanks again!


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