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 Key mapping Help
PostPosted: Fri Aug 25, 2006 11:17 am 
Newbie

Joined: Thu Jun 15, 2006 5:27 am
Posts: 13
Hello,

I've got a .hbm file generated by CodeSmith. Could someone help me correct what I wrote with NHibernate.Mapping.Attributes?

Cheers
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="xxx.Sorties, xxx" table="SORTIES">
    <id name="Id" type="String" unsaved-value="null">
      <column name="CODE_PIECE" length="30" sql-type="nvarchar" not-null="true" index="SORTIE_DE"/>
      <column name="DH_SORTIE" length="8" sql-type="datetime" not-null="true" index="aaaaaSORTIES_PK"/>
      <generator class="native" />
    </id>
    <property name="QteSortie" type="Single">
      <column name="QTE_SORTIE" length="4" sql-type="real" not-null="false"/>
    </property>
    <property name="MagSortie" type="String">
      <column name="MAG_SORTIE" length="20" sql-type="nvarchar" not-null="false"/>
    </property>
    <property name="AdrSortie" type="String">
      <column name="ADR_SORTIE" length="20" sql-type="nvarchar" not-null="false"/>
    </property>
    <property name="IntervSortie" type="String">
      <column name="INTERV_SORTIE" length="20" sql-type="nvarchar" not-null="false"/>
    </property>
    <property name="Equipement" type="String">
      <column name="EQUIPEMENT" length="30" sql-type="nvarchar" not-null="false"/>
    </property>
    <property name="Lib50" type="String">
      <column name="LIB50" length="50" sql-type="nvarchar" not-null="false"/>
    </property>
    <property name="UpsizeTs" type="Byte[]">
      <column name="upsize_ts" length="8" sql-type="timestamp" not-null="false"/>
    </property>
    <many-to-one name="Pieces" class="xxx.Pieces, Kpf.CoucheMetier">
      <column name="CODE_PIECE" length="30" sql-type="nvarchar" not-null="true" index="SORTIE_DE"/>
    </many-to-one>
  </class>
</hibernate-mapping>




Code:
using System;
using System.Collections;
using NHibernate;
using NHibernate.Mapping.Attributes;

namespace xxx
{
   /// <summary>
   ///   Classe liée à la table Sorties
   /// </summary>
    [NHibernate.Mapping.Attributes.Class(Table = "SORTIES")]
    public class Sorties
   {

      #region Private Members
      private string codePiece;
      private IList SortiesList;
      private DateTime dhSortie;
      private float qteSortie;
      private string magSortie;
      private string adrSortie;
      private string intervSortie;
      private string equipement;
      private string lib50;
      private byte[] upsizeTs;       
      #endregion

      #region Default ( Empty ) Class Constuctor
      /// <summary>
      /// default constructor
      /// </summary>
      public Sorties()
      {
      }
      #endregion // End of Default ( Empty ) Class Constuctor

      #region Required Fields Only Constructor
      /// <summary>
      /// required (not null) fields only constructor
      /// </summary>
        public Sorties(float qteSortie, string magSortie, string adrSortie, string intervSortie, string equipement, string lib50, byte[] upsizeTs)
      {
            this.qteSortie = qteSortie;
            this.magSortie = magSortie;
            this.adrSortie = adrSortie;
            this.intervSortie = intervSortie;
            this.equipement = equipement;
            this.lib50 = lib50;
            this.upsizeTs = upsizeTs;
      }
      #endregion // End Required Fields Only Constructor

      #region Public Properties
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.CompositeId()]
            [NHibernate.Mapping.Attributes.KeyManyToOne(1, Name = "CodePiece", Column = "CODE_PIECE", Class = "xxx.Pieces,xxx")]
        public string CodePiece
      {
         get
            {
                return this.codePiece;
            }

         set   
         {   
            if( value == null )
               throw new ArgumentOutOfRangeException("Null value not allowed for CodePiece", value, "null");
            
            if(  value.Length > 30)
               throw new ArgumentOutOfRangeException("Invalid value for CodePiece", value, value.ToString());
                this.codePiece = value;
         }
      }
         
        //public IList SortiesList
        //{
        //    get
        //    {
        //        return SortiesList;
        //    }
        //    set
        //    {
        //        SortiesList = value;
        //    }
        //}

      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.CompositeId()]
            [NHibernate.Mapping.Attributes.KeyProperty(1, Name = "DhSortie", Column = "DH_SORTIE", Type = "Datetime")]
        public DateTime DhSortie
      {
         get
            {
                return this.dhSortie;
            }
         set
         {
                this.dhSortie = value;
         }

      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "QTE_SORTIE")]
        public float QteSortie
      {
         get
            {
                return this.qteSortie;
            }
         set
         {
                this.qteSortie = value;
         }

      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "MAG_SORTIE")]
        public string MagSortie
      {
         get
            {
                return this.magSortie;
            }

         set   
         {   
            if(  value != null &&  value.Length > 20)
               throw new ArgumentOutOfRangeException("Invalid value for MagSortie", value, value.ToString());
                this.magSortie = value;
         }
      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "ADR_SORTIE")]
        public string AdrSortie
      {
         get
            {
                return this.adrSortie;
            }

         set   
         {   
            if(  value != null &&  value.Length > 20)
               throw new ArgumentOutOfRangeException("Invalid value for AdrSortie", value, value.ToString());
                this.adrSortie = value;
         }
      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "INTERV_SORTIE")]
        public string IntervSortie
      {
         get
            {
                return this.intervSortie;
            }

         set   
         {   
            if(  value != null &&  value.Length > 20)
               throw new ArgumentOutOfRangeException("Invalid value for IntervSortie", value, value.ToString());
                this.intervSortie = value;
         }
      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "EQUIPEMENT")]
        public string Equipement
      {
         get
            {
                return this.equipement;
            }

         set   
         {   
            if(  value != null &&  value.Length > 30)
               throw new ArgumentOutOfRangeException("Invalid value for Equipement", value, value.ToString());
                this.equipement = value;
         }
      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "LIB50")]
        public string Lib50
      {
         get
            {
                return this.lib50;
            }

         set   
         {   
            if(  value != null &&  value.Length > 50)
               throw new ArgumentOutOfRangeException("Invalid value for Lib50", value, value.ToString());
                this.lib50 = value;
         }
      }
         
      /// <summary>
      ///
      /// </summary>
        [NHibernate.Mapping.Attributes.Property(Column = "upsize_ts")]
        public byte[] UpsizeTs
      {
         get
            {
                return this.upsizeTs;
            }
         set
         {
                this.upsizeTs = value;
         }

      }
         
      #endregion
   }
}



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.