-->
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.  [ 4 posts ] 
Author Message
 Post subject: Composite Id of composite Id
PostPosted: Fri Jun 09, 2006 6:06 am 
Beginner
Beginner

Joined: Wed May 03, 2006 5:10 am
Posts: 32
Location: Monopoli - Italy
Hello everybody,

I need some help again... :)

I have the following situation in my db (semplified):

Code:
TABLE    [Test_Master] (
   [Id] [int] NOT NULL ,
   [RowVersion] [int] NULL
   CONSTRAINT [PK_Test_Master] PRIMARY KEY  CLUSTERED
   ([Id]) ON [PRIMARY]
)

TABLE [Test_Master2] (
   [Id] [int] NOT NULL ,
   [RowVersion] [int] NULL
   CONSTRAINT [PK_Test_Master2] PRIMARY KEY  CLUSTERED
   ([Id]) ON [PRIMARY]
)

TABLE    [Test_Tree] (
   [Id] [int] NOT NULL ,
   [RowVersion] [int] NULL
   CONSTRAINT [PK_Test_Tree] PRIMARY KEY  CLUSTERED
   ([Id]) ON [PRIMARY]
)

TABLE   [Test_Cross] (
   [IdMaster1] [int] NOT NULL ,
   [IdMaster2] [int] NOT NULL ,
   [RowVersion] [int] NULL
   CONSTRAINT [PK_Test_Cross] PRIMARY KEY  CLUSTERED
   (
         [IdMaster1],
      [IdMaster2]
   )  ON [PRIMARY] ,
   CONSTRAINT [FK_Test_Cross_Test_Master] FOREIGN KEY
   (
     [IdMaster1]
   ) REFERENCES [Test_Master] (
     [Id]
   ),
   CONSTRAINT [FK_Test_Cross_Test_Master2] FOREIGN KEY
   (
     [IdMaster2]
   ) REFERENCES [Test_Master2] (
     [Id]
   )
)

TABLE    [Test_Cross2] (
   [IdMaster1] [int] NOT NULL ,
   [IdMaster2] [int] NOT NULL ,
   [IdTree] [int] NOT NULL ,
   [RowVersion] [int] NULL
   CONSTRAINT [PK_Test_Cross2] PRIMARY KEY  CLUSTERED
   (
      [IdMaster1],
      [IdMaster2],
      [IdTree]
   )  ON [PRIMARY] ,
   CONSTRAINT [FK_Test_Cross2_Test_Cross] FOREIGN KEY
   (
      [IdMaster1],
      [IdMaster2]
   ) REFERENCES [Test_Cross] (
      [IdMaster1],
      [IdMaster2]
   ),
   CONSTRAINT [FK_Test_Cross2_Test_Tree] FOREIGN KEY
   (
     [IdTree]
   ) REFERENCES [Test_Tree] (
     [Id]
   )
)



and the related xml file is the following:

Code:
  <class name="ObjectModel.Test.Master, ObjectModel" table="Test_Master">
    <id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
      <generator class="hilo">
        <param name="table">NH_Key_Test</param>
        <param name="column">Test_Master</param>
        <param name="max_lo">0</param>
      </generator>
    </id>
    <version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
    <bag name="crosses" lazy="true" inverse ="true" cascade="all">
      <key column="IdMaster1" />
      <one-to-many class="ObjectModel.Test.Cross, ObjectModel" />
    </bag>
  </class>

  <class name="ObjectModel.Test.Master2, ObjectModel" table="Test_Master2">
    <id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
      <generator class="hilo">
        <param name="table">NH_Key_Test</param>
        <param name="column">Test_Master2</param>
        <param name="max_lo">0</param>
      </generator>
    </id>
    <version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
    <bag name="crosses" lazy="true" inverse ="true" cascade="all">
      <key column="IdMaster2" />
      <one-to-many class="ObjectModel.Test.Cross, ObjectModel" />
    </bag>
  </class>

  <class name="ObjectModel.Test.Cross, ObjectModel" table="Test_Cross">
    <composite-id>
      <key-many-to-one name="Master1" class="ObjectModel.Test.Master, ObjectModel" column="IdMaster1" />
      <key-many-to-one name="Master2" class="ObjectModel.Test.Master2, ObjectModel" column="IdMaster2" />
    </composite-id>
    <version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
    <bag name="cross2s" lazy="true" inverse ="true" cascade="all">
      <key>
        <column name="IdMaster1" />
        <column name="IdMaster2" />
      </key>
      <one-to-many class="ObjectModel.Test.Cross2, ObjectModel" />
    </bag>
  </class>

  <class name="ObjectModel.Test.Cross2, ObjectModel" table="Test_Cross2">
    <composite-id>
      <key-many-to-one name="Cross" class="ObjectModel.Test.Cross, ObjectModel">
      <column name="IdMaster1" />
      <column name="IdMaster2" />
      </key-many-to-one>     
      <key-many-to-one name="Tree" class="ObjectModel.Test.Tree, ObjectModel" column="IdTree" />
    </composite-id>
    <version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
  </class>

  <class name="ObjectModel.Test.Tree, ObjectModel" table="Test_Tree">
    <id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
      <generator class="hilo">
        <param name="table">NH_Key_Test</param>
        <param name="column">Test_Tree</param>
        <param name="max_lo">0</param>
      </generator>
    </id>
    <version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
    <bag name="cross2s" lazy="true" inverse ="true" cascade="all">
      <key column="IdTree" />
      <one-to-many class="ObjectModel.Test.Cross2, ObjectModel" />
    </bag>
  </class>


Everything works fine except for the class Cross2:

I executed the application setting show_sql=true: the sql query that NHibernate writes to load Cross2s is correct, it loads correctly each property in the object, but in the Cross (father) class NHibernate sets a collection with count=0:

Code:
        protected virtual System.Collections.IList cross2s
        {
            get
            {
                if (m_test_cross2s== null)
                {
                    m_test_cross2s=new System.Collections.ArrayList();               
                }
                return m_test_cross2s;
            }
            set
            {
                if (value != this.m_test_cross2s)
                {
                    m_test_cross2s = value;
                }
            }
        }



Could someone give me any idea?

Thanks in advance
Antonella


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 3:13 am 
Beginner
Beginner

Joined: Wed May 03, 2006 5:10 am
Posts: 32
Location: Monopoli - Italy
Please,

Could someone from NHibernate Team give me a help? Is it a bug?

_________________
Antonella


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 3:36 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Does it add elements to the collection afterwards? What is the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 3:51 am 
Beginner
Beginner

Joined: Wed May 03, 2006 5:10 am
Posts: 32
Location: Monopoli - Italy
Yes,

I can add elements to the collection and I can write them in the DB, but I cannot load them. After loading, the Cross2 collection is empty (count=0).

During the debug I observed that NHibernate fills the Cross2 properties, but in the Cross object (the father), when it assigns the collection, the value is empty:

Code:
protected virtual System.Collections.IList cross2s
        {
            get
            {
                if (m_test_cross2s== null)
                {
                    m_test_cross2s=new System.Collections.ArrayList();               
                }
                return m_test_cross2s;
            }
            set
            {
                if (value != this.m_test_cross2s)
                {
                    m_test_cross2s = value;
                }
            }
        }


_________________
Antonella


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.