-->
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.  [ 2 posts ] 
Author Message
 Post subject: deleted object would be re-saved by cascade
PostPosted: Thu Jul 07, 2011 2:06 pm 
Newbie

Joined: Thu Jul 07, 2011 1:56 pm
Posts: 2
Hello, first of all i beg your perdon if my english is not that well
Then, i've been looking around about this problem and i've found lots of information but i've tried lots and lots of things yet and not solving this problem.

i will copy all my code:


The example page:

aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/LayoutNew.Master" AutoEventWireup="true" CodeBehind="Prueba.aspx.cs" Inherits="OfficeMart.Prueba" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">


</asp:Content>

The cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DomainLayer.Objects;
using System.Text;
using System.Configuration;
using NHibernate;
using System.Net.Mail;
using OfficeMart.DataAccesLayer;


namespace OfficeMart
{
public partial class Prueba : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ISession Sesion;
ITransaction Transaction = null;
Sesion = SessionManager.OpenSession();
Transaction = Sesion.BeginTransaction();
BO_User user = (BO_User)Sesion.Load(typeof(BO_User), Request["User"]);
user.Categorys.Clear();
try
{
Sesion.SaveOrUpdate(user);
Transaction.Commit();
}
catch (Exception er)
{
Transaction.Rollback();
Response.Redirect("ErrorPage.aspx?Error=" + er.Message);
}
finally
{
Sesion.Close();
Sesion.Dispose();
}
}
}
}



the cs for hibernate:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainLayer.Objects
{
public class BO_User
{
public BO_User()
{ }

public BO_User(String UserName, String Password, String Name, String LastName, String Email, BO_Rol Rol, Boolean Enable, List<BO_CategoryUser> Categorys)
{
this.UserName = UserName;
this.Password = Password;
this.Name = Name;
this.LastName = LastName;
this.Email = Email;
this.Rol = Rol;
this.Enable = Enable;
this.Categorys = Categorys;
}

public String UserName { get; set; }
public String Password { get; set; }
public String Name { get; set; }
public String LastName { get; set; }
public String Email { get; set; }
public BO_Rol Rol { get; set; }
public Boolean Enable { get; set; }
public BO_Area Area { get; set; }
public BO_Company Company {get; set;}
public IList<BO_CategoryUser> Categorys { set; get; }

public override string ToString()
{
return this.LastName + ", " + this.Name + " - " + this.Rol.Description;
}
}
}



the xml of hibernate:


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
<class name="BO_User" table="USERS" lazy="false">

<id name="UserName" column="USERNAME" type="string" >
<generator class="assigned" />
</id>
<property name="Password" column="PASSWORD" type="string" not-null="true"/>
<property name="Name" column="NAME" type="string" not-null="true"/>
<property name="LastName" column="LASTNAME" type="string" not-null="true"/>
<property name="Email" column="EMAIL" type="string" not-null="true"/>
<many-to-one name="Rol" column="IDROL" class="BO_Rol" />
<property name="Enable" column="ENABLE" type="boolean" not-null="true"/>
<many-to-one name="Company" column="IDCOMPANY" class="BO_Company" />
<many-to-one name="Area" column="IDAREA" class="BO_Area" />
<bag name="Categorys" cascade="all-delete-orphan">
<key column="USERNAME"/>
<one-to-many class="BO_CategoryUser"/>
</bag>
</class>
</hibernate-mapping>





The error message:

deleted object would be re-saved by cascade (remove deleted object from associations): 100, of class: DomainLayer.Objects.BO_CategoryUser


what i need to do is simply delete the relationship bettwen The user (BO_User) and The BO_CategoryUser.


I'm using this middle-table (CategoryUser) to connect Users and categories.

This is the code of the CategoryUser table:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainLayer.Objects
{
public class BO_CategoryUser
{
public BO_CategoryUser()
{ }
public BO_CategoryUser(Int32 IdCategoryUser, BO_Category Category, BO_User User)
{
this.IdCategoryUser = IdCategoryUser;
this.Category = Category;
this.User = User;

}
public Int32 IdCategoryUser { get; set; }
public BO_Category Category { get; set; }
public BO_User User { get; set; }
}

}


And the xml


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
<class name="BO_CategoryUser" table="CATEGORY_USER" lazy="false">

<id name="IdCategoryUser" column ="IDCATEGORYUSER" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<many-to-one name="Category" column="IDCATEGORY" class="BO_Category" />
<many-to-one name="User" column="USERNAME" class="BO_User" />
</class>
</hibernate-mapping>



thanks in advance


Top
 Profile  
 
 Post subject: Re: deleted object would be re-saved by cascade
PostPosted: Thu Jul 07, 2011 3:35 pm 
Newbie

Joined: Thu Jul 07, 2011 1:56 pm
Posts: 2
I think the problem is the same in this: http://stackoverflow.com/questions/2763 ... all-orphan
But i really cant understand how to implement the solution.


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