-->
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: Collection problem
PostPosted: Wed May 13, 2009 4:27 pm 
Newbie

Joined: Wed May 13, 2009 4:07 pm
Posts: 1
Hi,

Im having a problem when I edit an object that has an IList.
Here are the codes for reference:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Build: with Personal Nhibernate template-->
  <class name="Fleury.Core.Domain.TblCommitteexUser,Fleury.Core" table="TblCommittee_x_User" lazy="true">
    <id name="CommitteeUserId" column="CommitteeUserId" type="int">
      <generator class="sequence">
        <param name="sequence">TBLCOMMITTEE_X_USER_COMMITTEEU</param>
      </generator>
    </id>
    <many-to-one name="TblCommittee" column="CommitteeId" cascade="save-update" not-null="true" />
    <many-to-one name="TblUser" column="UserId" cascade="none" not-null="true" />
    <property name="DateCreated" column="DateCreated" type="DateTime" />
    <property name="CommitteeOrder" column="CommitteeOrder" type="int" not-null="true" />
    <property name="Status" column="Status" type="Boolean" />
    <property name="Leader" column="Leader" type="Boolean" />
  </class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Build: with Personal Nhibernate template-->
  <class name="Fleury.Core.Domain.TblCommittee,Fleury.Core" table="TblCommittee" lazy="true">
    <id name="CommitteeId" column="CommitteeId" type="int">
      <generator class="sequence">
        <param name="sequence">TBLCOMMITTEE_COMMITTEEID_SEQ</param>
      </generator>
    </id>
    <property name="Title" column="Title" type="string" />
    <property name="Description" column="Description" type="string" />
    <property name="CreationDate" column="CreationDate" type="DateTime" />
    <property name="IsActive" column="IsActive" type="Boolean" />
    <bag name="TblCommitteeXUser" inverse="true" lazy="true" cascade="all-delete-orphan">
      <key column="CommitteeId" />
      <one-to-many class="Fleury.Core.Domain.TblCommitteexUser,Fleury.Core" />
    </bag>
    <bag name="TblEvent" inverse="true" lazy="true" cascade="none">
      <key column="CommitteeId" />
      <one-to-many class="Fleury.Core.Domain.TblEvent,Fleury.Core" />
    </bag>
   
  </class>
</hibernate-mapping>
Code:
int count = 1;
if (oTblCommittee == null)
    oTblCommittee = new TblCommittee();
oTblCommittee.Title = txtTitulo.Text;
oTblCommittee.IsActive = (rbtnAtivo.SelectedValue == "1") ? true : false;
oTblCommittee.CreationDate = DateTime.Now;
oTblCommittee.TblCommitteeXUser = new List<TblCommitteexUser>();
foreach (ListItem oListItem in lstAvaliadores.Items)
{   
    TblCommitteexUser oTblCommitteexUser = new TblCommitteexUser();
    oTblCommitteexUser.TblUser = new TblUser();
    oTblCommitteexUser.TblUser.UserId = Convert.ToInt32(oListItem.Value);
    oTblCommitteexUser.DateCreated = DateTime.Now;
    oTblCommitteexUser.TblCommittee = oTblCommittee;
    oTblCommitteexUser.CommitteeOrder = count;
    oTblCommittee.TblCommitteeXUser.Add(oTblCommitteexUser);
    count++;
}

Then I try to edit an existing committee, changing or deleting the Users in the Committee.

After the last piece of code, i call "saveorupdate" passing as parameter the "oTblCommittee".
It inserts the new items in the TblCommitteexUser, updates the title and creationdate, but doesn't delete the old TblCommitteexUsers.

What am I doing wrong?


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.