-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with Component and one-to-many
PostPosted: Thu Apr 06, 2006 5:59 am 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
Question
Are wrong the mappings or is it a bug?

Hibernate version: 1.0.2

Classes:
Code:
public class Operation
{
   private int id;
   private PaymentPlan paymentPlan;
       
       //getter and setter
}

public class PaymentPlan
{
   private DateTime expirationDate;
   private int numberOfPayments;
   private IList payments;
       
        //getter and setter
}

public class Payment
{
   private int id;
   private int amount;
   private DateTime expiration;
   private PaymentPlan paymentPlan;

        //getter and setter
}


Mapping documents:
Code:
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
  <class name="Castle.ActiveRecord.Tests.Model.Nested.Operation, Castle.ActiveRecord.Tests" table="Operation" lazy="false">
    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <component name="PaymentPlan">
      <property name="ExpirationDate" access="property" column="ExpirationDate" type="System.DateTime" />
      <property name="NumberOfPayments" access="property" column="NumberOfPayments" type="Int32" />
      <bag name="Payments" access="property" table="Payment" lazy="false">
        <key column="PaymentPlan" />
        <one-to-many class="Castle.ActiveRecord.Tests.Model.Nested.Payment, Castle.ActiveRecord.Tests" />
      </bag>
    </component>
  </class>
</hibernate-mapping>


and


Code:
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
  <class name="Castle.ActiveRecord.Tests.Model.Nested.Payment, Castle.ActiveRecord.Tests" table="Payment" lazy="false">
    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <property name="Amount" access="property" column="Amount" type="Int32" />
    <property name="Expiration" access="property" column="Expiration" type="System.DateTime" />
    <many-to-one name="PaymentPlan" access="property" class="Castle.ActiveRecord.Tests.Model.Nested.PaymentPlan, Castle.ActiveRecord.Tests" column="PaymentPlan" />
  </class>
</hibernate-mapping>


Full stack trace of any exception that occurs:
Code:
TestCase 'Castle.ActiveRecord.Tests.JoinedSubClassWithNestedClassTestCase.Operations' failed: System.NullReferenceException : Object reference not set to an instance of an object.
   at NHibernate.Cfg.Mapping.GetIdentifierType(Type persistentClass)
   at NHibernate.Type.ManyToOneType.GetReferencedType(IMapping mapping)
   at NHibernate.Type.ManyToOneType.GetColumnSpan(IMapping mapping)
   at NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping)
   at NHibernate.Mapping.Property.IsValid(IMapping mapping)
   at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping)
   at NHibernate.Mapping.RootClass.Validate(IMapping mapping)
   at NHibernate.Cfg.Configuration.Validate()
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   D:\Progetti\Castle\ActiveRecord\Castle.ActiveRecord\Framework\SessionFactoryHolder.cs(115,0): at Castle.ActiveRecord.Framework.SessionFactoryHolder.GetSessionFactory(Type type)
   D:\Progetti\Castle\ActiveRecord\Castle.ActiveRecord\Framework\SessionFactoryHolder.cs(140,0): at Castle.ActiveRecord.Framework.SessionFactoryHolder.CreateSession(Type type)
   d:\progetti\castle\activerecord\castle.activerecord\framework\activerecordbase.cs(178,0): at Castle.ActiveRecord.ActiveRecordBase.DeleteAll(Type type)
   d:\progetti\castle\activerecord\castle.activerecord.tests\model\nested\operation.cs(31,0): at Castle.ActiveRecord.Tests.Model.Nested.Operation.DeleteAll()
   d:\progetti\castle\activerecord\castle.activerecord.tests\nestedclasswithbelongstotestcase.cs(24,0): at Castle.ActiveRecord.Tests.JoinedSubClassWithNestedClassTestCase.Operations()


Name and version of the database you are using:
MSSql 2000




Thank you!
Antonio.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 12:00 pm 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
I've wrote 2 test in NH, the first that use the Payment mapping that you can see in the above post, the second that haven't this line

Code:
Code:
<many-to-one name="PaymentPlan" access="property" class="Castle.ActiveRecord.Tests.Model.Nested.PaymentPlan, Castle.ActiveRecord.Tests" column="PaymentPlan" />



The first test fails because NH expects itself that the class used in a many-to-one relation, on the many side, should be a "PersistentClass" but not being it, it fails.
from the NH source, in
NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys

Code:
Code:
PersistentClass referencedClass = ( PersistentClass ) classes[ fk.ReferencedClass ];



The second test works because NH creates and search for a column named "PaymentPlan" in the table Payment that contain the FK, I suppose that it deduce it from tha one-to-many relation present in the component class definition in the mapping.

There is a way that permit to use a component class as a FK in a many-to-one relation?

Antonio.


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