-->
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: Mapping an ordered list
PostPosted: Thu Feb 26, 2009 8:26 am 
Newbie

Joined: Wed Jan 07, 2009 6:46 am
Posts: 1
NHibernate version: 2.0.0.4000

I have two classes like this in C#, SQL code and mappings files:
Code:
public class R
    {

        private int Id;
        private string Name;
        private IList W;

        public R()
        {
            Name = string.Empty;
        }

        public virtual void setId(int value) { Id = value; }
        public virtual int getId() { return Id; }

        public virtual void setName(string value) { Name = value; }
        public virtual string getName() { return Name; }

        public virtual void setW(IList value) { W = value; }
        public virtual IList getW() { return W; }
   }
   
public class W
    {
      private int Id;
      private double V;

      public W(double v)
      {
          V = v;
      }

      public virtual void setId(int value) { Id = value; }
      public virtual int getId() { return Id; }

      public virtual void setV(double v) { V = v; }
      public virtual double getV() { return V; }
   }
   
CREATE TABLE W(
  Id int identity primary key,
  V float null
)

CREATE TABLE R (
  Id int identity primary key,
  Name varchar(64) null,
)

CREATE TABLE WR (
  IdR int not null,
  Position int null,
  primary key (IdR)
)
alter table WR add constraint WRFK0 FOREIGN KEY(IdR) references R(Id)

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" namespace="X.Classes" assembly="X">
  <class name="X.Classes.R, X" table="R" lazy="false">
    <id name="Id" access="field" column="Id">
      <generator class="native" />
    </id>
    <property name="Name" access="field" column="Name" type="String" length="64" not-null="false"/>
    <list name="W" table="WR" lazy="true">
      <key column="IdR"/>
      <index column="Position"/>
    </list>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" namespace="X.Classes" assembly="X">
  <class name="X.Classes.W, X" table="W" lazy="false">
    <id name="Id" access="field" column="Id">
      <generator class="native" />
    </id>
    <property name="V" access="field" column="V" type="Double"/>
  </class>
</hibernate-mapping>


I want to store an ordered list of W objects in R. The mapping file doesn´t work.


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.