Foros del Web » Programación para mayores de 30 ;) » .NET »

deleted object would be re-saved by cascade

Estas en el tema de deleted object would be re-saved by cascade en el foro de .NET en Foros del Web. Hola, disculpen los moleste con este asunto, se que hay muchísima información sobre él pero he probado mil cosas distintas y no he llegado a ...
  #1 (permalink)  
Antiguo 07/07/2011, 12:10
 
Fecha de Ingreso: julio-2011
Mensajes: 2
Antigüedad: 12 años, 9 meses
Puntos: 0
deleted object would be re-saved by cascade

Hola, disculpen los moleste con este asunto, se que hay muchísima información sobre él pero he probado mil cosas distintas y no he llegado a la solución

Copio mi código


La página de ejemplo que hice:

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>

El 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();
}
}
}
}



El cs para 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;
}
}
}



El xml para 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>





El mensaje de error

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

Lo que necesito hacer es simplemente eliminar la relación entre el usuario (BO_User) y las categorías BO_CategoryUser


Estoy usando esta tabla en el medio para relacionar usuarios con categorías


Este es el código del cs de la tabla

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; }
}

}


Y este el 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>



Desde ya muchas gracias.
  #2 (permalink)  
Antiguo 07/07/2011, 13:37
 
Fecha de Ingreso: julio-2011
Mensajes: 2
Antigüedad: 12 años, 9 meses
Puntos: 0
Respuesta: deleted object would be re-saved by cascade

Creo que es este mismo problema pero realmente no entiendo como lo soluciona.
http://stackoverflow.com/questions/2763985/how-do-i-change-a-childs-parent-in-nhibernate-when-cascade-is-delete-all-orphan

Etiquetas: cascade, deleted, net, object
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:37.