-->
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.  [ 3 posts ] 
Author Message
 Post subject: Use CompositeId attribute with class
PostPosted: Tue Nov 15, 2005 6:19 pm 
Newbie

Joined: Wed Dec 22, 2004 12:04 pm
Posts: 7
I am trying to use the composite id with a class to define my composite id.

Code:
[NHibernate.Mapping.Attributes.CompositeId()]
[NHibernate.Mapping.Attributes.Generator(Class="assigned")]
public MyClassKey MyClassKey
{
   get
{
  return myClassKey;
}
set
{
  myClassKey=value;
}
}


MyClassKey object have 2 property define with attribute

When a generate my DDL i receive this error message.

Code:
CVSM.NMP.NMPTest.TestUserService.TestGenerateDDL : NHibernate.MappingException : The element 'urn:nhibernate-mapping-2.0:composite-id' has incomplete content. Expected 'urn:nhibernate-mapping-2.0:key-property urn:nhibernate-mapping-2.0:key-many-to-one'. An error occurred at , (15, 6).
  ----> System.Xml.Schema.XmlSchemaException : The element 'urn:nhibernate-mapping-2.0:composite-id' has incomplete content. Expected 'urn:nhibernate-mapping-2.0:key-property urn:nhibernate-mapping-2.0:key-many-to-one'. An error occurred at , (15, 6).


I know i miss an attribute or something

tks

Francis


Top
 Profile  
 
 Post subject: more info
PostPosted: Wed Nov 16, 2005 11:43 am 
Newbie

Joined: Wed Dec 22, 2004 12:04 pm
Posts: 7
The best example i can foud to explain my problem i found it in the hibernate test.



Code:
public class ClassWithCompositeId
{
   private Id _id;
   private int _oneProperty;

   public ClassWithCompositeId(){}
   public ClassWithCompositeId(Id id )
   {
      _id = id;
   }

   public Id Id
   {
      get {return _id;}
   }

   public int OneProperty
   {
      get {return _oneProperty;}
      set {_oneProperty = value;}
   }
}



Code:
public class Id
{
   private string _keyString;
   private short _keyShort;
   private System.DateTime _keyDateTime;

   public Id() {}

   public Id(string keyString, short keyShort, System.DateTime keyDateTime) {
      _keyString = keyString;
      _keyShort = keyShort;
      _keyDateTime = keyDateTime;
   }

   public string KeyString {
      get { return _keyString;}
      set { _keyString = value;}
   }

   public System.DateTime KeyDateTime {
      get { return _keyDateTime;}
   }

   public override int GetHashCode() {
      return _keyString.GetHashCode();
   }

   public override bool Equals(object obj) {
      Id otherObj = obj as Id;

      if(otherObj==null) return false;
         if(otherObj.KeyString.Equals(this.KeyString)) return true;

      return false;

   }
}



What attribute i have to put to have the righ mapping. My goal is to have this kind of file

Code:
<class
      name="NHibernate.Test.CompositeId.ClassWithCompositeId, NHibernate.Test"
      table="class_w_com_id"
   >
      <composite-id name="Id" class="NHibernate.Test.CompositeId.Id, NHibernate.Test" access="nosetter.camelcase-underscore">
         <key-property name="KeyString" column="string_" type="String(20)" length="20" />
         <key-property name="KeyShort" column="short_" access="field.camelcase-underscore"/>
         <key-property name="KeyDateTime" column="date_" type="DateTime" access="nosetter.camelcase-underscore"/>
      </composite-id>
      
      <property name="OneProperty" column="one_property"/>
   </class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 10:54 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
First, you forgot the positions (1, 2...); you should always set them when you have more than one attributes on the same property.

The mapping of <composite-id> is done exactly like in XML, so read its documentation: http://nhibernate.sourceforge.net/nh-docs/html/mapping.html#mapping-declaration-compositeid

And AFAIK, you can't use your custom class as Identifier; put its content in your entity class...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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

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.