-->
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.  [ 1 post ] 
Author Message
 Post subject: Composite element and native key
PostPosted: Tue Apr 03, 2007 11:49 am 
Newbie

Joined: Tue Apr 03, 2007 11:29 am
Posts: 4
Hi all,

I'm new on NHibernate and i have a problem with composite element in bags.

I'm working with NHibernate 1.2 RC1, .NET 2.0 and SQL Server 2005

So here's my mapping file


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Dppr.Biologie.Transport" assembly="Dppr.Biologie">
   <class name="InfosPatient" table="T_INFOS_PATIENT" lazy="false">
      <id name="Identifiant" column="PAT_ID_N" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <bag name="Diagnostics" table="T_DIAGNOSTIC" cascade="all" lazy="false">
         <key column="PAT_ID_N"/>
         <composite-element class="Diagnostic">
            <property column="DIA_ID_N" type="Int32" name="Identifiant" insert="false" update="false" />
            <property column="DIA_CODE_C" type="String" name="Code" length="20" />
         </composite-element>
      </bag>
      <property column="PAT_IDDEMANDEUR_C" type="String" name="IdPatientDemandeur" length="16" />
   </class>
</hibernate-mapping>


and my C# Code for the transport object:
Code:
// Identifiant du patient
private int identifiant = 0;
/// <summary>
/// Identifiant du patient
/// </summary>
/// L'identifiant est un identifiant sequentiel, donc d'aucune utilité pour l'utilisateur
[XmlIgnore]
public virtual int Identifiant
{
   get { return this.identifiant; }
   set { this.identifiant = value; }
}

// Identifiant du patient attribué par le demandeur
private string idPatientDemandeur;
public virtual string IdPatientDemandeur
{
   get { return this.idPatientDemandeur; }
   set { this.idPatientDemandeur = value; }
}


// Diagnostic
private System.Collections.Generic.IList<Diagnostic> diagnostics;
[XmlIgnore]
public virtual System.Collections.Generic.IList<Diagnostic> Diagnostics
{
   get
   {
      if (this.diagnostics == null)
      {
         this.diagnostics = new System.Collections.Generic.List<Diagnostic>();
      }
      return this.diagnostics;
   }
   set { this.diagnostics = value; }
}


When I try to insert data in the table "Insert" and "update" attributes of the DIA_ID_N property don't seem to be effective. Indeed NHibernate tries to insert data in the field.

I am looking for a way of preventing data from being inserted in this field. Any idea?

here is the error message I am getting from NHibernate:

Quote:
NHibernate.ADOException: could not insert collection: [Dppr.Biologie.Transport.Analyse.Diagnostics#1] ---> System.Data.SqlClient.SqlException: Cannot insert explicit value for identity column in table 'T_DIAGNOSTIC' when IDENTITY_INSERT is set to OFF..


Thanks in advance for your answers.
Any help will be appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.