XML validation error: El elemento 'class' en espacio de nombres 'urn:nhibernate-mapping-2.2' tiene un elemento secundario 'id' en espacio de nombres 'urn:nhibernate-mapping-2.2' no válido. Lista esperada de elementos posibles: 'discriminator, natural

90 views
Skip to first unread message

Javier Sanchez

unread,
Jun 23, 2016, 9:35:36 AM6/23/16
to NHibernate-Hispano
Hola

Tengo la tabla

CREATE TABLE dbo.TBLPEDIDOSPROLIN
 (
 IDPEDIDOPRO       INT NOT NULL,
 IDPEDIDOPROLIN    INT NOT NULL,
 IDARTICULO        INT NULL,
 CANTIDAD          INT CONSTRAINT DF_TBLPEDIDOSPROLIN_CANTIDAD DEFAULT ((0)) NULL,
 IDUNIDADTIPO      CHAR (2) CONSTRAINT DF_TBLPEDIDOSPROLIN_IDUNIDADTIPO DEFAULT ('') NOT NULL,
 CANTIDADUNIDAD    INT CONSTRAINT DF_TBLPEDIDOSPROLIN_CANTIDADUNIDAD DEFAULT ((1)) NOT NULL,
 REFPROVEEDOR      VARCHAR (25) NULL,
 ATRIB1            VARCHAR (50) NULL,
 ATRIB2            VARCHAR (50) NULL,
 ATRIB3            VARCHAR (50) NULL,
 IMPORTCIONESTADO  INT NULL,
 IMPORTACIONESTADO INT NULL,
 CONSTRAINT PK_TBLPEDIDOSPROLIN PRIMARY KEY (IDPEDIDOPRO, IDPEDIDOPROLIN),
 CONSTRAINT FK_TBLPEDIDOSPROLIN_TBLPEDIDOSPROCAB FOREIGN KEY (IDPEDIDOPRO) REFERENCES dbo.TBLPEDIDOSPROCAB (IDPEDIDOPRO),
 CONSTRAINT FK_TBLPEDIDOSPROLIN_TBLARTICULOS FOREIGN KEY (IDARTICULO) REFERENCES dbo.TBLARTICULOS (IDARTICULO)
 )
GO

Con el mapeo

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    assembly="WebServiceQuero"
    namespace="Hibernate.Entities">

  <class name="TblPedidosProLin">
    <id column="IdPedidoPro">
      <generator class="assing" />
    </id>
    <id column="IdPedidoProLin">
      <generator class="assing" />
    </id>
    <property name="Cantidad" />
    <property name="IdArticulo" />
    <property name="ImportacionEstado" />
  </class>
</hibernate-mapping>

Y la clase

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Hibernate.Entities
{
    public class TblPedidosProLin
    {
        private int idpedidopro;
        private int idpedidoprolin;
        private int idarticulo;
        private int cantidad;
        private int importacionEstado;

        public virtual int IdPedidoPro
        {
            get { return idpedidopro; }
            set { idpedidopro = value; }
        }

        public virtual int Cantidad
        {
            get { return cantidad; }
            set { cantidad = value; }
        }

        public virtual int IdArticulo
        {
            get { return idarticulo; }
            set { idarticulo = value; }
        }

        public virtual int ImportacionEstado
        {
            get { return importacionEstado; }
            set { importacionEstado = value; }
        }

        public virtual int IdPedidoProLin
        {
            get { return idpedidoprolin; }
            set { idpedidoprolin = value; }
        }
    }
}

¿Por que me sale este error
XML validation error: El elemento 'class' en espacio de nombres 'urn:nhibernate-mapping-2.2' tiene un elemento secundario 'id' en espacio de nombres 'urn:nhibernate-mapping-2.2' no válido. Lista esperada de elementos posibles: 'discriminator, natural?

Saludos



Carlos Cocom

unread,
Jun 23, 2016, 7:01:41 PM6/23/16
to nhibernat...@googlegroups.com
La sintaxis que usa es para surrogate-key sin embargo quieres usar natural-key. 

En nhibernate y java existe un concepto que se llama PoID significa que cada entidad (fila en la bd ) tiene un id unico lo que hace mas sencillo las relaciones y las operaciones de cascada en delete o updates.

Para usar dos o mas propiedades como id de cada entidad tienes que usar el elemento "composite-id" y en tu clase sobreescribir los métodos
GetHasCode  y Equals.


--
--
Para escribir al Grupo, hágalo a esta dirección: NHibernat...@googlegroups.com
Para más, visite: http://groups.google.com/group/NHibernate-Hispano
---
Has recibido este mensaje porque estás suscrito al grupo "NHibernate-Hispano" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a nhibernate-hisp...@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages