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.  [ 6 posts ] 
Author Message
 Post subject: NHibernate.Mapping.Attributes - cannot set column order
PostPosted: Fri Jun 30, 2006 4:51 am 
Newbie

Joined: Fri Jun 30, 2006 4:17 am
Posts: 4
Hi,

I use NHibernate.Mapping.Attributes for mapping declarations and SchemaExport class for generating ddl. I've noticed that HbmSerializer always places <many-to-one> elements after <property> element. It's a real pain for me if I declare multicolumn unique keys or indexes with property and foreign key column. I cannot set correct column order:

Hibernate version: 1.2.0 Alpha 1
Class definition:
Code:
   
    [Class]
    public class Course
    {
        private int _id;
        [Id(0, Column="Id", TypeType = typeof(int) )]
            [Generator(1, Class = "native")]
        public virtual int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private Product _product;
        [ManyToOne(0, ForeignKey="FK_Course_Product"),
            Column(1, Name = "ProductID", NotNull=true, UniqueKey = "0")]
        public virtual Product Product
        {
            get { return _product; }
            set { _product = value; }
        }

        private string _name;
        [Property (0),
           Column(1, Name = "Name", NotNull = true, Length=50, UniqueKey = "0")]
        public virtual string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    }


Xml generated by HbmSerializer :
Code:
  <class name="Test.Domain.Course, Test.Core">
    <id column="Id" type="Int32">
      <generator class="native" />
    </id>
    <property name="Name">
      <column name="Name" length="50" not-null="true" unique-key="0" />
    </property>
    <many-to-one name="Product" foreign-key="FK_Course_Product">
      <column name="ProductID" not-null="true" unique-key="0" />
    </many-to-one>
  </class>


I expect unique key (ProductID, Name) so I need <column name="ProductID"> before <column name="Name">. How can I perform this?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 01, 2006 2:06 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Do you mean that you want this?
Code:
  <class name="Test.Domain.Course, Test.Core">
    <id column="Id" type="Int32">
      <generator class="native" />
    </id>
    <many-to-one name="Product" foreign-key="FK_Course_Product">
      <column name="ProductID" not-null="true" unique-key="0" />
    </many-to-one>
    <property name="Name">
      <column name="Name" length="50" not-null="true" unique-key="0" />
    </property>
  </class>

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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 01, 2006 2:10 pm 
Newbie

Joined: Fri Jun 30, 2006 4:17 am
Posts: 4
Yes, I do. I really need this.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 3:55 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
To solve many ordering issues, NHMA follows the order of the XML mapping schema; so it is not possible to change this order arbitrarily.

The next release of NHMA will come with a new attribute called "RawXml"; so you may use it as a work around to insert the ManyToOne before the Property.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 5:28 am 
Newbie

Joined: Fri Jun 30, 2006 4:17 am
Posts: 4
I don't understand this restriction. In nhibernate-mapping-2.0.xsd I see the following:

Code:
<xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:element ref="property"/>
  <xs:element ref="many-to-one"/>
  <xs:element ref="one-to-one"/>
  <xs:element ref="component"/>
  <xs:element ref="dynamic-component"/>
  <xs:element ref="any"/>
  <xs:element ref="map"/>
  <xs:element ref="set"/>
  <xs:element ref="list"/>
  <xs:element ref="bag"/>
  <xs:element ref="idbag"/>
  <xs:element ref="array"/>
  <xs:element ref="primitive-array"/>
</xs:choice>


It's a choice, not a sequence. Where is ordering that you mentioned?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 11:24 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHMA follows the order of elements; even if the XSD allows them to come in any order.

The reason is that it solves many issues.
It would be possible to write the elements in any order, but it would make it impossible to map elements taking sub-elements... (collections and like)

_________________
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.  [ 6 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.