-->
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: CreateCriteria many-to-one
PostPosted: Sun Oct 02, 2005 3:42 pm 
Newbie

Joined: Sat Sep 03, 2005 1:52 am
Posts: 8
Hey

I have some association classes where I need to get specific instances of the class by using session.CreateCriteria and by searching for two specific values of two one-to-many properties.

Here is the essential code:

ICriteria _criteria=_session.CreateCriteria(type);

_criteria.Add(Expression.Eq(property1, propertyval1));
_criteria.Add(Expression.Eq(property2, propertyval2));

IList _ilist;

try
{
_ilist = _criteria.List();
}
catch (Exception ex)
{
throw ex;
}

I get this exception:
Object reference not set to an instance of an object.
I know that there is nothing wrong with the properties or the values.
I also know that the correct values are in the database.
I can get the correct lists from both classes associated through this class.
The problem is that no result is returned.
Am I doing anything wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 3:45 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please post complete exception stack trace and your mappings.


Top
 Profile  
 
 Post subject: Stack trace and mappings
PostPosted: Mon Oct 03, 2005 1:29 am 
Newbie

Joined: Sat Sep 03, 2005 1:52 am
Posts: 8
Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
VZ.Model.VZBaseDataAccess.GetCurrentLanguage(Type returntype, String parentname, Object parent) in c:\a_vs\vz.model\vzbasedataaccess.cs:363
VZ.Model.Language.GetCurrentLanguage() in c:\a_vs\vz.model\language.cs:113
VZ.Model.Language.get_Language_Language() in c:\a_vs\vz.model\language.cs:65
VZTestWeb.VZLanguageMenu.Page_PreRender(Object sender, EventArgs e) in c:\inetpub\wwwroot\vztestweb\vzlanguagemenu.ascx.cs:69
System.Web.UI.Control.OnPreRender(EventArgs e)
System.Web.UI.Control.PreRenderRecursiveInternal()
System.Web.UI.Control.PreRenderRecursiveInternal()
System.Web.UI.Control.PreRenderRecursiveInternal()
System.Web.UI.Control.PreRenderRecursiveInternal()
System.Web.UI.Control.PreRenderRecursiveInternal()
System.Web.UI.Page.ProcessRequestMain()

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="VZ.Model.Language_Language, VZ.Model" table="Language_Language" >
<id name="ID" column="ID" type="Int32" unsaved-value="-1">
<generator class="identity" />
</id>
<version name="Version" column="Version" type="Int32" unsaved-value="-1" />
<property name="Name" column="Name" />
<property name="Timestamp" column="Timestamp" update="false" insert="false" />
<many-to-one name="Language"
class="VZ.Model.Language, VZ.Model"
column="LanguageID" />
<many-to-one name="TextLanguage"
class="VZ.Model.Language, VZ.Model"
column="TextLanguageID"
/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 1:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, as you can see, the error is in your code. Maybe it makes some assumptions that NHibernate breaks.


Top
 Profile  
 
 Post subject: Error found - data was missing
PostPosted: Mon Oct 03, 2005 5:00 am 
Newbie

Joined: Sat Sep 03, 2005 1:52 am
Posts: 8
Hello sergey

I found the error.
I knew there are no errors in my code, because I have made all kinds of doublecheck.
By accident it happened that I had problems with another object where I
had written the data directly in the table. The cause was I had null-values in the Version-field that I map to.
So I corrected this to a 0 in all records and it worked.
Did the same thing with the table I use in my question and now it works.
So you were correct that there were assumptions that NHibernate broke.
Namely that the Version of course expects an integer value in the mapped field.

I will use this opportunity to thank you and the rest of the team for doing this work. You deserve medals and a lot of credits for this.
I am one of the guys who have put a lot of work into making my own Dal's
with stored procedures and I believe your work makes most of this work superfluous in the near future and makes my work more fun and interesting. Thank you!!


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.