Menu

In don't recover a one to one associate

2004-08-31
2004-09-07
  • Nobody/Anonymous

    My code is :

    Dim a As Ventas.Cliente = New Ventas.Cliente
            a.CodigoCliente = 6
            a.Find(a)
    generate the next error:
    Excepcin no controlada del tipo 'AToMSFramework.RetrieveException' en atomsframework.dll

    Informacin adicional: Could not set attribute FormaPago (Value Type: FormaPago) in CPersistentObject::SetAttributeValue.
    La conversin del tipo 'FormaPago' al tipo 'FormaPago' no es vlida.

    My XML is:
    <class name="Cliente" table="cliente" database="erp">
            <attribute name="CodigoCliente" column="codigocliente" find="true" key="primary" />
            <attribute name="Nombre" column="nombre" />
            <attribute name="Apellidos" column="apellidos" />
            <attribute name="Nif" column="nif" />
            <attribute name="RazonSocial" column="razonsocial" />
            <attribute name="FechaAlta" column="fechaalta" />
            <attribute name="FormaPago"/>
            <attribute name="CodigoFormaPago" column="codigoformapago" />
            <attribute name="FormaEnvio"/>
            <attribute name="CodigoFormaEnvio" column="codigoformaenvio" />       
            <attribute name="Direcciones"/>       
            <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
            <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
        </class>
        <association fromClass="Cliente"
            toClass="FormaPago"
            cardinality="oneToOne"
            target="FormaPago"
            retrieveAutomatic="true"
            deleteAutomatic="false"
            saveAutomatic="false"
            inverse="false">
            <entry fromAttribute="CodigoFormaPago" toAttribute="CodigoFormaPago"/>
        </association>

    <class name="FormaPago" table="formapago" database="erp" namespace="ERP" assemblypath="C:\Proyectos\ERP\bin\ERP.dll">
            <attribute name="CodigoFormaPago" column="codigoformapago" find="true" key="primary" proxy="true"/>
            <attribute name="Nombre" column="nombre" />
            <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
            <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
        </class>

    Saludos

    Victor (Madrid - Spain)

     
    • Richard Banks

      Richard Banks - 2004-08-31

      Hi Victor,

      You should make sure that the classes are declared before any associations that use them.

      Just try reordering your XML mapping and see if you still have the problem.

       
    • Nobody/Anonymous

      I have first declared FormaPago, second Cliente and finally the association.

      I have the same problem

       
    • Richard Banks

      Richard Banks - 2004-09-01

      It's possible that you have a code problem in your class.  Check the set method of your FormaPago property in the Cliente class.

      Since you're using classes from two different assemblies you might need to check your references are correct (since you are getting a type conversion error).

      You might need to post some more code that isolates the problem.

      - Richard.

       
    • victor Saquicela

      My code is the following:
      XML
      <?xml version="1.0" encoding="utf-8" ?>
      <map>
          <database name="erp" class="CODBCDatabase">
              <parameter name="name" value="DRIVER={SAP DB};SERVER=kersan20;DATABASE=ERP;UID=ERP;PWD=ERP" />
              <parameter name="user" value="erp" />
              <parameter name="password" value="erp" />
              <parameter name="OIDTable" value="OID" />
          </database>
          <class name="Serial" table="serial" database="erp">
              <attribute name="nombre" column="nombre" find="true" key="primary" />
              <attribute name="Valor" column="valor" />
              <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
              <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
          </class>
          <class name="FormaPago" table="FormaPago" database="erp" namespace="ERP" assemblypath="C:\Proyectos\ERP\bin\ERP.dll">
              <attribute name="CodigoFormaPago" column="CodigoFormaPago" find="true" key="primary" proxy="true"/>
              <attribute name="Nombre" column="nombre" />
              <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
              <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
          </class>
          <class name="FormaEnvio" table="formaenvio" database="erp" namespace="ERP" assemblypath="C:\Proyectos\ERP\bin\ERP.dll">
              <attribute name="CodigoFormaEnvio" column="codigoformaenvio" find="true" key="primary" />
              <attribute name="Nombre" column="nombre" />
              <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
              <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
          </class>
          <class name="Cliente" table="cliente" database="erp" namespace="Ventas" assemblypath="C:\Proyectos\Ventas\bin\Ventas.dll">
              <attribute name="CodigoCliente" column="codigocliente" find="true" key="primary" />
              <attribute name="Nombre" column="nombre" />
              <attribute name="Apellidos" column="apellidos" />
              <attribute name="Nif" column="nif" />
              <attribute name="RazonSocial" column="razonsocial" />
              <attribute name="FechaAlta" column="fechaalta" />
              <attribute name="FormaPago"/>
              <attribute name="CodigoFormaPago" column="CodigoFormaPago" />
              <attribute name="FormaEnvio"/>
              <attribute name="CodigoFormaEnvio" column="CodigoFormaEnvio" />       
              <attribute name="Direcciones"/>       
              <attribute name="CreatedDate" column="CreatedDate" timestamp="true" />
              <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true" />
          </class>
          <association fromClass="Cliente"
              toClass="FormaPago"
              cardinality="oneToOne"
              target="FormaPago"
              retrieveAutomatic="true"
              deleteAutomatic="false"
              saveAutomatic="false"
              inverse="false">
              <entry fromAttribute="CodigoFormaPago" toAttribute="CodigoFormaPago"/>
          </association>
          <association fromClass="Cliente"
              toClass="FormaEnvio"
              cardinality="oneToOne"
              target="Formaenvio"
              retrieveAutomatic="true"
              deleteAutomatic="false"
              saveAutomatic="false"
              inverse="false">
              <entry fromAttribute="CodigoFormaEnvio" toAttribute="CodigoFormaEnvio"/>
          </association>
      </map>

      CLIENTE
      Imports AToMSFramework
      Public Class Cliente
          Inherits CPersistentObject
          Private _codigoCliente As Integer
          Private _nombre As String
          Private _apellidos As String
          Private _nif As String
          Private _razonSocial As String
          Private _fechaAlta As Date
          Private _direcciones As CPersistentCollection
          Private _formaPago As ERP.FormaPago 'Forma de Pago del cliente
          Private _codigoFormaPago As Integer
          Private _formaEnvio As ERP.FormaEnvio 'Forma de Envio del cliente
          Private _codigoFormaEnvio As Integer

          Public Sub New(ByVal codigo As Integer, ByVal nombre As String, ByVal apellidos As String, ByVal nif As String, ByVal razonsocial As String, ByVal fechaalta As String, Optional ByVal fPago As Integer = 0, Optional ByVal fEnvio As Integer = 0)
              Me._codigoCliente = codigo
              Me._nombre = nombre
              Me._apellidos = apellidos
              Me._nif = nif
              Me._razonSocial = razonsocial
              Me._fechaAlta = fechaalta
          End Sub
          Public Sub New()
              _direcciones = New CPersistentCollection
              _direcciones.ContainerObject = Me
          End Sub

          Public Function verificarBaja() As Boolean

          End Function

          Public Function verificarModificacion() As Boolean

          End Function

          Public Function agregarDireccion(ByVal direccion As ERP.Direccion) As Boolean
              _direcciones.Add(direccion)
          End Function

          Public Function eliminarDireccion(ByVal direccion As ERP.Direccion) As Boolean
              _direcciones.Remove(direccion)
          End Function
          Public Property CodigoCliente() As Integer
              Get
                  Return _codigoCliente
              End Get

              Set(ByVal Value As Integer)
                  If _codigoCliente <> Value Then
                      _codigoCliente = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property

          Public Property Nombre() As String
              Get
                  Return _nombre
              End Get

              Set(ByVal Value As String)
                  If _nombre <> Value Then
                      _nombre = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property

          Public Property Apellidos() As String
              Get
                  Return _apellidos
              End Get
              Set(ByVal Value As String)
                  If _apellidos <> Value Then
                      _apellidos = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property

          Public Property Nif() As String
              Get
                  Return _nif
              End Get
              Set(ByVal Value As String)
                  If _nif <> Value Then
                      _nif = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property

          Public Property RazonSocial() As String
              Get
                  Return _razonSocial
              End Get
              Set(ByVal Value As String)
                  If _razonSocial <> Value Then
                      _razonSocial = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property

          Public Property FechaAlta() As Date
              Get
                  Return _fechaAlta
              End Get
              Set(ByVal Value As Date)
                  If _fechaAlta <> Value Then
                      _fechaAlta = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Property FormaPago() As ERP.FormaPago
              Get
                  Return _formaPago
              End Get
              Set(ByVal Value As ERP.FormaPago)
                  If _formaPago Is Nothing And (Not Value Is Nothing) Then
                      _formaPago = Value
                      SetDirtyFlag()
                      Exit Property
                  End If
                  If Value Is Nothing Then
                      _formaPago = Nothing
                      SetDirtyFlag()
                      Exit Property
                  End If
                  If Not _formaPago.Equals(Value) Then
                      _formaPago = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Property FormaEnvio() As ERP.FormaEnvio
              Get
                  Return _formaEnvio
              End Get
              Set(ByVal Value As ERP.FormaEnvio)
                  If _formaEnvio Is Nothing And (Not Value Is Nothing) Then
                      _formaEnvio = Value
                      SetDirtyFlag()
                      Exit Property
                  End If
                  If Value Is Nothing Then
                      _formaEnvio = Nothing
                      SetDirtyFlag()
                      Exit Property
                  End If
                  If Not _formaEnvio.Equals(Value) Then
                      _formaEnvio = Value
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Property CodigoFormaPago() As Integer
              Get
                  If _formaPago Is Nothing Then
                      Return _codigoFormaPago
                  Else
                      Return _formaPago.CodigoFormaPago
                  End If
              End Get
              Set(ByVal Value As Integer)
                  If Not _formaPago Is Nothing Then
                      If _formaPago.CodigoFormaPago <> Value Then
                          _formaPago.CodigoFormaPago = Value
                          SetDirtyFlag()
                      End If
                  End If
                  _codigoFormaPago = Value
              End Set
          End Property
          Public Property CodigoFormaEnvio() As Integer
              Get
                  If _formaEnvio Is Nothing Then
                      Return _codigoFormaenvio
                  Else
                      Return _formaEnvio.CodigoFormaEnvio
                  End If
              End Get
              Set(ByVal Value As Integer)
                  If Not _formaEnvio Is Nothing Then
                      If _formaEnvio.CodigoFormaEnvio <> Value Then
                          _formaEnvio.CodigoFormaEnvio = Value
                          SetDirtyFlag()
                      End If
                  End If
                  _codigoFormaenvio = Value
              End Set
          End Property
          Public Property Direcciones() As CPersistentCollection
              Get
                  Return _direcciones
              End Get
              Set(ByVal Value As CPersistentCollection)
                  _direcciones = Value
                  SetDirtyFlag()
              End Set
          End Property

          Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject
              Return New Cliente
          End Function

          Public Overrides Function IsValid() As Boolean
              Return True
          End Function
      End Clas

      Imports AToMSFramework
      Public Class FormaPago
          Inherits CPersistentObject
          Private _CodigoFormaPago As Integer
          Private _nombre As String

          Public Sub New()

          End Sub
          Public Sub New(ByVal codigo As Integer, ByVal nombre As String)
              Me._CodigoFormaPago = codigo
              Me._nombre = nombre
          End Sub

          Public Property CodigoFormaPago() As Integer
              Get
                  Return _CodigoFormaPago ' Retorna el valor almacenado en la variable local           
              End Get
              Set(ByVal Value As Integer)
                  If _CodigoFormaPago <> Value Then
                      _CodigoFormaPago = Value ' Almacenar el valor en la varible local
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Property Nombre() As String
              Get
                  Return _nombre ' Retorna el valor almacenado en la variable local           
              End Get
              Set(ByVal Value As String)
                  If _nombre <> Value Then
                      _nombre = Value ' Almacenar el valor en la varible local
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject
              Return New FormaPago
          End Function

          Public Overrides Function IsValid() As Boolean
              Return True
          End Function
      End Class

      Imports AToMSFramework
      Public Class FormaEnvio
          Inherits CPersistentObject
          Private _CodigoFormaEnvio As Integer
          Private _nombre As String
          Public Sub New()

          End Sub
          Public Sub New(ByVal codigo As Integer, ByVal nombre As String)
              Me._CodigoFormaEnvio = codigo
              Me._nombre = nombre
          End Sub
          Public Property CodigoFormaEnvio() As Integer
              Get
                  Return _CodigoFormaEnvio ' Retorna el valor almacenado en la variable local           
              End Get
              Set(ByVal Value As Integer)
                  If _CodigoFormaEnvio <> Value Then
                      _CodigoFormaEnvio = Value ' Almacenar el valor en la varible local
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Property Nombre() As String
              Get
                  Return _nombre ' Retorna el valor almacenado en la variable local           
              End Get
              Set(ByVal Value As String)
                  If _nombre <> Value Then
                      _nombre = Value ' Almacenar el valor en la varible local
                      SetDirtyFlag()
                  End If
              End Set
          End Property
          Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject
              Return New FormaEnvio
          End Function

          Public Overrides Function IsValid() As Boolean
              Return True
          End Function
      End Class

      Saludos

      Victor (Madrid - Spain)

       
    • Richard Banks

      Richard Banks - 2004-09-02

      Hi Victor,

      Your property for FormaPago is here...

      Public Property FormaPago() As ERP.FormaPago
      Get
        Return _formaPago
      End Get
      Set(ByVal Value As ERP.FormaPago)
        If _formaPago Is Nothing And (Not Value Is Nothing) Then
          _formaPago = Value
          SetDirtyFlag()
          Exit Property
        End If
        If Value Is Nothing Then
          _formaPago = Nothing
          SetDirtyFlag()
          Exit Property
        End If
        If Not _formaPago.Equals(Value) Then
          _formaPago = Value
          SetDirtyFlag()
        End If
      End Set
      End Property

      In the first If statement you've got a problem...
        If _formaPago Is Nothing And (Not Value Is Nothing) Then

      if Value is Nothing then "Not Value" will cause an error.  You probably want

        If _formaPago Is Nothing And Not (Value Is Nothing) Then

      However there is an easier way to do your property as follows:

      Public Property FormaPago() As ERP.FormaPago
      Get
        Return _formaPago
      End Get
      Set(ByVal Value As ERP.FormaPago)
        If Not CPersistentObject.Equals(_formaPago,Value) then
          _formaPage = Value
          SetDirtyFlag()
        End If
      End Set
      End Property

      - Richard.

       
    • victor Saquicela

      Hi,
      I try with the code:
      Public Property FormaPago() As ERP.FormaPago
      Get
      Return _formaPago
      End Get
      Set(ByVal Value As ERP.FormaPago)
      If Not CPersistentObject.Equals(_formaPago,Value) then
      _formaPage = Value
      SetDirtyFlag()
      End If
      End Set
      End Property

      but nothing

      its produce a mistake:

      Excepcin no controlada del tipo 'AToMSFramework.RetrieveException' en atomsframework.dll

      Informacin adicional: Could not set attribute FormaPago (Value Type: FormaPago) in CPersistentObject::SetAttributeValue.
      La conversin del tipo 'FormaPago' al tipo 'FormaPago' no es vlida.

      I think that the problem can be that FormaPago is ERP.dll and cliente is Ventas.dll ?

      Saludos

      Victor (Madrid - Spain)

       
    • Richard Banks

      Richard Banks - 2004-09-03

      OK,

      I've found the problem.  It's a bit of a head scratcher but it's best explained by the fact that your assemblypath in the XML is different to that referenced by the application when you compile.

      There's an explanation of this at http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx

      I've reproduced it locally and I'm just trying to think of a way around it.

      - Richard.

       
    • Richard Banks

      Richard Banks - 2004-09-03

      OK,

      The latest code in CVS should fix the problem now.

      You don't need to specify the assembly path in the XML file - just the namespace - and everything should work properly.

      Phew!

      - Richard.

       
    • victor Saquicela

      Hi,
      I continue having the same problem.

      Excepcin no controlada del tipo 'AToMSFramework.RetrieveException' en atomsframework.dll

      Informacin adicional: Could not set attribute FormaPago (Value Type: FormaPago) in CPersistentObject::SetAttributeValue.
      La conversin del tipo 'FormaPago' al tipo 'FormaPago' no es vlida.

      forgives the inconveniences

      Saludos

      Victor (Madrid -Spain)

       
    • Richard Banks

      Richard Banks - 2004-09-05

      Hi Victor,

      To help me isolate the problem further, can you do the following:

      1.  In VStudio go to Debug->Exceptions and change Common Language Runtime Exceptions to Break Into the Debugger when the exception is thrown (it's normally set to Continue)

      2.  Run your code in Debug mode.

      3.  When you get the exception occurring in SetAttributeValue have a look at your Call Stack. 

      Post the call stack here so I can see where the error is coming from.

      - Richard.

       
    • Nobody/Anonymous

      Call Stack is here:
           [<Cdigo de no usuario>]   
      >    atomsframework.dll!AToMSFramework.CPersistentObject.setAttributeValue(String pName = "FormaPago", Object Value = {ERP.FormaPago}) Lnea 480    Basic
           atomsframework.dll!AToMSFramework.CPersistenceBroker.retrievePrivateObject(AToMSFramework.CPersistentObject obj = {Ventas.Cliente}, AToMSFramework._CConnection conn = {AToMSFramework.CODBCConnection}, Boolean useFind = True, Boolean useCache = True) Lnea 595 + 0x42 bytes    Basic
           atomsframework.dll!AToMSFramework.CPersistenceBroker.retrieveObject(AToMSFramework.CPersistentObject obj = {Ventas.Cliente}, Boolean useFind = True, Boolean useCache = True) Lnea 184 + 0x1b bytes    Basic
           atomsframework.dll!AToMSFramework.CPersistentObject.Find(AToMSFramework.CPersistentObject obj = {Ventas.Cliente}, Boolean useCache = True) Lnea 956 + 0x14 bytes    Basic
           atomsframework.dll!AToMSFramework.CPersistentObject.Find(AToMSFramework.CPersistentObject obj = {Ventas.Cliente}) Lnea 973 + 0xb bytes    Basic
           Principal.exe!Principal.FormVictor.Button20_Click(Object sender = {System.Windows.Forms.Button}, System.EventArgs e = {System.EventArgs}) Lnea 593 + 0xd bytes    Basic
           [<Cdigo de no usuario>]   
           Principal.exe!Principal.FormVictor.Main() Lnea 1 + 0x1d bytes    Basic

      Mistake is:
      Excepcin del tipo 'AToMSFramework.AttributeValueException' en atomsframework.dll

      Informacin adicional: Could not set attribute FormaPago (Value Type: FormaPago) in CPersistentObject::SetAttributeValue.
      La conversin del tipo 'FormaPago' al tipo 'FormaPago' no es vlida.

       
    • Nobody/Anonymous

      Hi,

      All right, with last CVS to not especified assembly.

      Thank you

       
    • Richard Banks

      Richard Banks - 2004-09-06

      Hi Victor,

      So it's working properly now?

      There's a delay between the Developer CVS and the public CVS copies - when you got the code last time, it's possible that the public CVS hadn't updated yet.

      - Richard.

       
    • Nobody/Anonymous

      All right

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.