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: one-to-many inserting null rows
PostPosted: Fri Jun 23, 2006 1:06 am 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
Hibernate version:
1.0.20 Beta

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Devtoo.Data" assembly="Devtoo.Data">
<class name="Devtoo.Data.Article, Devtoo.Data" table="tblArticle" lazy="false">
<id name="ArticleId" column="ArticleId" unsaved-value="0">
<generator class="identity"></generator>
</id>
<property name="Title"></property>
<property name="SubmitDate"></property>
<property name="Body"></property>
<property name="AuthorId"></property>
<property name="Diggs"></property>
<many-to-one name="Author" class="Devtoo.Data.User" column="AuthorId" insert="false" update="false"></many-to-one>
<one-to-one name="ApprovedDate" foreign-key="ArticleId" class="Devtoo.Data.ArticleQueue"></one-to-one>
<list name="Comments" cascade="all-delete-orphan" generic="true" lazy="true">
<key column="ArticleId"></key>
<index column="CommentId"></index>
<one-to-many class="Devtoo.Data.ArticleComment, Devtoo.Data"></one-to-many>
</list>
</class>
</hibernate-mapping>



<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Devtoo.Data" assembly="Devtoo.Data">
<class name="Devtoo.Data.ArticleComment, Devtoo.Data" table="tblArticleComment" lazy="false">
<id name="CommentId" column="CommentId" unsaved-value="0" >
<generator class="identity" />
</id>
<property name="ArticleId"></property>
<property name="AuthorId"></property>
<property name="SubmitDate"></property>
<property name="Body"></property>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Article article1 = (Article)session.Load(typeof(Article), 1);

Name and version of the database you are using:
MSSQL 2005



When I load the object article1.Comments it actually has 2 items in the IList<ArticleComment> property rather than just 1 ( I only have 1 row in the database) and the first index Comments[0] is null... How can I resolve this?


Top
 Profile  
 
 Post subject: used a bag
PostPosted: Fri Jun 23, 2006 1:26 am 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
I changed it to

<bag name="Comments" lazy="true">
<key column="ArticleId"></key>
<one-to-many class="Devtoo.Data.ArticleComment"></one-to-many>
</bag>

and it worked perfectly. Why doesn't generic lists work?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 1:34 am 
Newbie

Joined: Mon Jun 19, 2006 1:14 pm
Posts: 6
using the bag with generic works fine, just can't use list.


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.