Gracias Gustavo, es lo del arbol y el bosque ...
De todos modos hay algo que no entiendo. El script me lo enviaron a peticion mia y habria sido generado por el administrador del sqlserver (2000) a partir de la base de datos.

Alguna idea?

Saludos,
Raul.


Gustavo Ringel escribió:
Raul, en la excepcion dice que el problema es con el indice unico IX_Clientes

Ese indice unico no esta en los scripts que tu decis que crean la base. O sea que tenes que fijarte que indice unico crearon y agregarle el ID quizas :).

Gustavo.

2010/1/18 Raul Lopez <[email protected] <mailto:[email protected]>>

    Hola, estoy interactuando con una base de datos que tiene algunas
    tablas que ya estaban creadas (son utilizadas por otras
    aplicaciones ya existentes en la empresa sin ORM).

    En una de esas tablas, al insertar un registro,
    me permite hacerlo en la primera oportunidad (tabla vacia), pero
    al intentar insertar un segundo registro genera el siguiente error:

    NHibernate.Exceptions.GenericADOException: could not insert:
    [RecursosHumanos.Domain.Cliente][SQL: INSERT INTO
    NombreDeLaEmpresa.dbo.Clientes (Codigo, Ejecutable, Tipo, RUC,
    Nombre, Domicilio, Mail, Contacto, Telefono, Fax) VALUES (?, ?, ?,
    ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()] --->
    System.Data.SqlClient.SqlException: Cannot insert duplicate key
    row in object 'Clientes' with unique index 'IX_Clientes'.
    The statement has been terminated.
     en System.Data.SqlClient.SqlConnection.OnError(SqlException
    exception, Boolean breakConnection)
     en
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection)
     en
    
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
    stateObj)
     en System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
    SqlCommand cmdHandler, SqlDataReader dataStream,
    BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
    stateObj)
     en System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
     en System.Data.SqlClient.SqlDataReader.get_MetaData()
     en
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
    ds, RunBehavior runBehavior, String resetOptionsString)
     en
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream,
    Boolean async)
     en
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method, DbAsyncResult result)
     en
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method)
     en System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    behavior, String method)
     en
    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
    behavior)
     en
    System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
     en NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
     en
    
NHibernate.Id.IdentityGenerator.InsertSelectDelegate.ExecuteAndExtract(IDbCommand
    insert, ISessionImplementor session)
     en
    NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo
    insertSQL, ISessionImplementor session, IBinder binder)
     --- Fin del seguimiento de la pila de la excepción interna ---


    El script con el que generaron la tabla es:

    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE TABLE [dbo].[Clientes](
           [IdCuenta] [int] IDENTITY(1,1) NOT NULL,
           [Codigo] [nvarchar](50) NOT NULL,
           [Ejecutable] [bit] NOT NULL,
           [Tipo] [int] NOT NULL,
           [RUC] [nvarchar](50) NULL,
           [Nombre] [nvarchar](50) NOT NULL,
           [Domicilio] [nvarchar](50) NULL,
           [Mail] [nvarchar](50) NULL,
           [Contacto] [nvarchar](50) NULL,
           [Telefono] [nvarchar](50) NULL,
           [Fax] [nvarchar](50) NULL,
           [ActualizadoTS] [timestamp] NULL,
     CONSTRAINT [PK_Clientes] PRIMARY KEY CLUSTERED
    (
           [IdCuenta] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
    IGNORE_DUP_KEY =
    OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR =
    90) ON
    [PRIMARY]
    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[Clientes] ADD  CONSTRAINT [DF_Clientes_Ejecutable]
    DEFAULT (1) FOR [Ejecutable]
    GO

    ALTER TABLE [dbo].[Clientes] ADD  CONSTRAINT [DF_Clientes_Tipo]
     DEFAULT (0)
    FOR [Tipo]
    GO



    El mapping que yo estoy usando:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    assembly="RecursosHumanos.Domain" namespace="RecursosHumanos.Domain">
           <class name="Cliente" table="Clientes">

                   <id name="IdCuenta" column="IdCuenta" type="Int32"
    unsaved-value="0">
                           <generator class="identity"/>
                   </id>
                   <property column="Codigo" type="String"
    name="Codigo" not-null="true" length="50" />
                   <property column="Ejecutable" type="Boolean"
    name="Ejecutable" not-null="true" />
                   <property column="Tipo" type="Int32" name="Tipo"
    not-null="true" />
                   <property column="RUC" type="String" name="Ruc"
    length="50" />
                   <property column="Nombre" type="String"
    name="Nombre" not-null="true" length="50" />
                   <property column="Domicilio" type="String"
    name="Domicilio" length="50" />
                   <property column="Mail" type="String" name="Mail"
    length="50" />
                   <property column="Contacto" type="String"
    name="Contacto" length="50" />
                   <property column="Telefono" type="String"
    name="Telefono" length="50" />
                   <property column="Fax" type="String" name="Fax"
length="50" /> </class>
    </hibernate-mapping>


    Esto sucede en el servidor remoto, ya que en mi maquina anda bien.

    Desde ya agradezco cualquier aporte.

    Saludos,
    Raul.

    --
    Para escribir al Grupo, hágalo a esta dirección:
    [email protected]
    <mailto:[email protected]>
    Para más, visite: http://groups.google.com/group/NHibernate-Hispano


-- 
Para escribir al Grupo, hágalo a esta dirección: 
[email protected]
Para más, visite: http://groups.google.com/group/NHibernate-Hispano

Responder a