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.  [ 1 post ] 
Author Message
 Post subject: Object not fully populated when Loaded directly after Save
PostPosted: Tue Nov 06, 2007 11:11 am 
Newbie

Joined: Tue Apr 06, 2004 6:37 am
Posts: 17
Location: Oslo, Norway
Hi

I'm having some problems regarding loading of objects in an ASP.NET webapplication. I have an online questionnaire system which allows users to create questions and submit answers. My problem is that when saving an answer collection and then loads it on the same request, the answer objects are not fully populated.

I have an AnswerCollection object which contains an IDictionary of Answer objects. Each Answer object has a reference to a Question object.

Let's say I have two methods. One for saving answer collections and one for loading answer collections. The saving works fine. Loading also works fine if I load the AnswerCollection in a new request. However, if I first save an AnswerCollection and then loads it in the same request, the Question-reference in the Answer-object is null. Why is my Question object null

Code:
public int SaveAnswerCollection(AnswerCollection answerCollection)
{
   NHibernateSession.SaveOrUpdate(answerCollection);
   NHibernateSession.Flush();
   return answerCollection.Id;
}


public int GetAnswerCollection(int id)
{
    return (AnswerCollection)NHibernateSession.Load(typeof(AnswerCollection), id);
}


Code:
AnswerCollection ac = new AnswerCollection();
ac.Question = someQuestion;

SaveAnswerCollection(ac);

AnswerCollection ac2 = GetAnswerCollection(ac.Id);

ac2.Question <-- Question is null!!




Hibernate version:
NHibernate 1.2.0

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

<class name="AnswerCollection, model" table="AnswerCollection">
<id name="Id" type="integer" column="Id">
<generator class="identity"/>
</id>

<many-to-one name="QuestionCollection"
class="QuestionCollection, model"
column="QuestionCollection"/>

<map name="answers" cascade="all-delete-orphan" lazy="false">
<key column="answercollection" />
<index column="aorder" type="integer" />
<one-to-many class="Answer, model" />
</map>

</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

<class name="QuestionCollection, model" table="QuestionCollection">
<id name="Id" type="int" column="Id">
<generator class="identity"/>
</id>

<map name="QuestionCollectionQuestion" cascade="all-delete-orphan" lazy="false">
<key column="QuestionCollection" />
<index column="QuestionOrder" type="integer" />
<one-to-many class="QuestionCollectionQuestion, model" />
</map>

<property name="Mandatory" column="Mandatory" type="boolean" />
<property name="TimeStamp" column="TimeStamp" type="datetime" />

</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

<class name="Answer, model" table="Answer">
<id name="id" type="int" column="Id">
<generator class="identity"/>
</id>
<many-to-one name="answercollection"
class="AnswerCollection, model"
column="answercollection"/>
<many-to-one name="Question"
class="Question, model"
column="aorder"/>
</class>
</hibernate-mapping>







Name and version of the database you are using:
MS SQL Server 2005

[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.