Here are the hbm files that are generated when I include the [Any]
attribute on the Journal.Journalable property.

On Wed, Aug 5, 2009 at 9:46 PM, Markus Zywitza<[email protected]> wrote:
> Can you send in the generated hbm files? You'll have to specify debug="true"
> in your config for them to be written to disk.
>
> -Markus
>
> 2009/8/5 jsmorris <[email protected]>
>>
>> Thanks for your continued help Markus.  I now understand what you are
>> saying about the HasMany side of this relationship and was able to
>> make it work!  But, now the BelongsTo/Any side of the relationship is
>> throwing an error.  I attempted to use this mapping on my Journal
>> object to reference which object this Journal belongs to (either Foo,
>> Bar, or any other IJournalable object).
>>
>>        [Any(IdType = typeof(Int32), MetaType = typeof(IJournalable),
>> TypeColumn = "JournalableType", IdColumn = "JournalableId", Cascade =
>> CascadeEnum.SaveUpdate)]
>>        [Any.MetaValue("Foo", typeof(Foo))]
>>        [Any.MetaValue("Bar", typeof(Bar))]
>>        public IJournalable Journalable { get; set; }
>>
>> But, got the below errors.  I am not sure, even reading the inner
>> exception, that I know where to start looking.
>>
>> Jason
>>
>> System.NullReferenceException: Object reference not set to an instance
>> of an object.
>> at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindAny(XmlNode node, Any
>> model, Boolean isNullable)
>> at NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode
>> node, PersistentClass model, IDictionary`2 inheritedMetas, UniqueKey
>> uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId)
>> at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node,
>> HbmClass classSchema, IDictionary`2 inheritedMetas)
>> at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode
>> parentNode, IDictionary`2 inheritedMetas)
>> at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
>> at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
>> NHibernate.MappingException: Could not compile the mapping document:
>> (string)
>> at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
>> at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
>> at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
>> at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument
>> document)
>> at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String
>> name)
>> at NHibernate.Cfg.Configuration.AddXml(String xml, String name)
>> at NHibernate.Cfg.Configuration.AddXmlString(String xml)
>> at Castle.ActiveRecord.ActiveRecordStarter.AddXmlString(Configuration
>> config, String xml, ActiveRecordModel model) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 761
>> Castle.ActiveRecord.Framework.ActiveRecordException: Error adding
>> information from class Intel.TraX.Tests.Data.Store.Journal to
>> NHibernate. Check the inner exception for more information
>> at Castle.ActiveRecord.ActiveRecordStarter.AddXmlString(Configuration
>> config, String xml, ActiveRecordModel model) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 765
>> at
>> Castle.ActiveRecord.ActiveRecordStarter.AddXmlToNHibernateCfg(ISessionFactoryHolder
>> holder, ActiveRecordModelCollection models) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 751
>> at
>> Castle.ActiveRecord.ActiveRecordStarter.RegisterTypes(ISessionFactoryHolder
>> holder, IConfigurationSource source, IEnumerable`1 types, Boolean
>> ignoreProblematicTypes) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 933
>> at Castle.ActiveRecord.ActiveRecordStarter.Initialize(IConfigurationSource
>> source, Type[] types) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 200
>> at Castle.ActiveRecord.ActiveRecordStarter.Initialize(Assembly[]
>> assemblies, IConfigurationSource source, Type[] additionalTypes) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:
>> line 223
>> at
>> Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility.InitializeFramework(ArrayList
>> assemblies) in
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\Facilities\ActiveRecordIntegration\Castle.Facilities.ActiveRecordIntegration\ActiveRecordFacility.cs:
>> line 147
>> at Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility.Init()
>> in
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\Facilities\ActiveRecordIntegration\Castle.Facilities.ActiveRecordIntegration\ActiveRecordFacility.cs:
>> line 107
>> at Castle.MicroKernel.Facilities.AbstractFacility.Init(IKernel kernel,
>> IConfiguration facilityConfig) in
>>
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\InversionOfControl\Castle.MicroKernel\Facilities\AbstractFacility.cs:
>> line 69
>> at Castle.MicroKernel.DefaultKernel.AddFacility(String key, IFacility
>> facility) in
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\InversionOfControl\Castle.MicroKernel\DefaultKernel.cs:
>> line 515
>> at Castle.Windsor.WindsorContainer.AddFacility(String key, IFacility
>> facility) in
>> c:\TeamCity\buildAgent\work\7e4107d1782544ec\InversionOfControl\Castle.Windsor\WindsorContainer.cs:
>> line 261
>> at Intel.TraX.Web.IoCContainer.RegisterFacilities() in IoCContainer.cs:
>> line 57
>> at Intel.TraX.Web.IoCContainer..ctor(String configFileName) in
>> IoCContainer.cs: line 34
>> at Intel.TraX.Tests.BasePersistenceTestFixture.TestFixtureSetUp() in
>> BasePersistenceTestFixture.cs: line 37
>>
>>
>>
>> On Wed, Aug 5, 2009 at 10:18 AM, Markus Zywitza<[email protected]>
>> wrote:
>> > Maybe I was unclear. BelongsTo won't help here, Any is the reight
>> > attribute.
>> > You have to specify
>> >
>> > HasMany(typeof(Journal), ColumnKey="...", Table="...")
>> >
>> > This should work.
>> > -Markus
>> > 2009/8/4 jsmorris <[email protected]>
>> >>
>> >> Moved from dev list...my apologies for asking my question on the wrong
>> >> list.
>> >>
>> >> I now understand that I need the BelongsTo, but my problem is
>> >> constructing the correct BelongsTo in this situation.  All my attempts
>> >> have failed.
>> >>
>> >> So, my Journal class needs a BelongsTo to associate it to either a Foo
>> >> or Bar, so if I define this
>> >>
>> >>  [BelongsTo("JournalableId", Table = "Journals")]
>> >>  public IJournalable Journalable { get; set; }
>> >>
>> >> I get the the error message.  If I type the property to either of my
>> >> concrete types Foo or Bar, I do not get an error.
>> >>
>> >>  [BelongsTo("JournalableId", Table = "Journals")]
>> >>  public Foo Journalable { get; set; }
>> >>
>> >> or
>> >>
>> >>  [BelongsTo("JournalableId", Table = "Journals")]
>> >>  public Bar Journalable { get; set; }
>> >>
>> >> I feel that I need to be able to specify a type to the BelongsTo.  I
>> >> was attempting to use the Any attribute to specify my metatype,
>> >> IJournalable, as well as the concrete types, Foo and Bar,  for this
>> >> association.  I believe that my Journals table would end up with
>> >> columns Id, JournalableId, JournalableType where JournalableType would
>> >> be either Foo or Bar.
>> >>
>> >> Is this type of association even possible?
>> >>
>> >> Thanks,
>> >> Jason
>> >>
>> >>
>> >>
>> >> On Fri, Jul 31, 2009 at 7:34 PM, Markus
>> >> Zywitza<[email protected]>
>> >> wrote:
>> >> > Hint: It's already explained in the exception: If you don't have a
>> >> > BelongsTo
>> >> > (Any doesn't count), you need to specify ColumnKey and Table.
>> >> >
>> >> > -Markus
>> >> >
>> >> > 2009/7/31 jsmorris <[email protected]>
>> >> >>
>> >> >> I am having trouble setting up my AR relationships.  I have tried so
>> >> >> many things, but nothing seems to work.  Here is what I am trying to
>> >> >> do.
>> >> >>
>> >> >> Foo has many Journals.  Bar has many Journals. A Journal can belong
>> >> >> to
>> >> >> either Foo or Bar.
>> >> >>
>> >> >> If I try the mapping I have below, I get the following error
>> >> >>
>> >> >> Castle.ActiveRecord.Framework.ActiveRecordException: ActiveRecord
>> >> >> tried to infer details about the relation Bar.Journals but it could
>> >> >> not find a 'BelongsTo' mapped property in the target type
>> >> >> Intel.TraX.Tests.Data.Store.Journal
>> >> >>
>> >> >> I am probably way off on what needs to be done, but I am looking for
>> >> >> any help to point me in the right direction.
>> >> >>
>> >> >> Thanks,
>> >> >> Jason
>> >> >>
>> >> >>    [ActiveRecord]
>> >> >>    public class Journal : DomainObject<Journal>
>> >> >>    {
>> >> >>        [Any(typeof(Int32), MetaType = typeof(IJournalable),
>> >> >> TypeColumn = "JournalableType", IdColumn = "JournalableId", Cascade
>> >> >> =
>> >> >> CascadeEnum.SaveUpdate)]
>> >> >>        [Any.MetaValue("Foo", typeof(Foo))]
>> >> >>        [Any.MetaValue("Bar", typeof(Bar))]
>> >> >>        public IJournalable Journalable { get; set; }
>> >> >>    }
>> >> >>
>> >> >>    public interface IJournalable {}
>> >> >>
>> >> >>    [ActiveRecord]
>> >> >>    public class Foo : DomainObject<Foo>, IJournalable
>> >> >>    {
>> >> >>        [HasMany(ColumnKey = "JournalableId")]
>> >> >>        public IList<Journal> Journals { get; set; }
>> >> >>    }
>> >> >>
>> >> >>    [ActiveRecord]
>> >> >>    public class Bar : DomainObject<Bar>, IJournalable
>> >> >>    {
>> >> >>        [HasMany(ColumnKey = "JournalableId")]
>> >> >>        public IList<Journal> Journals { get; set; }
>> >> >>    }
>> >> >> }
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > >
>> >> >
>> >> >>
>> >
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

<?xml version="1.0" encoding="utf-16"?>

<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">

  <class name="Company.Project.Libraries.Data.Store.Foo, Company.Project.Libraries.Data.Store" table="Foos">

    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">

      <generator class="native">

      </generator>

    </id>

    <bag name="Journals" access="property" table="Journals" lazy="false" cascade="all-delete-orphan">

      <key column="JournalableId" />

      <one-to-many class="Company.Project.Libraries.Data.Store.Journal, Company.Project.Libraries.Data.Store" />

    </bag>

  </class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-16"?>

<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">

  <class name="Company.Project.Libraries.Data.Store.Journal, Company.Project.Libraries.Data.Store" table="Journals">

    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">

      <generator class="native">

      </generator>

    </id>

    <property name="Note" access="property" type="String">

      <column name="Note"/>

    </property>

    <property name="CreatedAt" access="property" type="System.DateTime">

      <column name="CreatedAt"/>

    </property>

    <property name="CreatedBy" access="property" type="String">

      <column name="CreatedBy"/>

    </property>

    <any name="Journalable" access="property" id-type="Int32" meta-type="Company.Project.Libraries.Data.Store.IJournalable, Company.Project.Libraries.Data.Store" cascade="save-update">

      <meta-value value="Foo" class="Company.Project.Libraries.Data.Store.Foo, Company.Project.Libraries.Data.Store" />

      <meta-value value="Bar" class="Company.Project.Libraries.Data.Store.Bar, Company.Project.Libraries.Data.Store" />

      <column name="JournalableType" />

      <column name="JournalableId" />

    </any>

    <bag name="Details" access="property" table="JournalDetails" lazy="false" cascade="all">

      <key column="JournalId" />

      <one-to-many class="Company.Project.Libraries.Data.Store.JournalDetail, Company.Project.Libraries.Data.Store" />

    </bag>

  </class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-16"?>

<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">

  <class name="Company.Project.Libraries.Data.Store.JournalDetail, Company.Project.Libraries.Data.Store" table="JournalDetails">

    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">

      <generator class="native">

      </generator>

    </id>

    <property name="Key" access="property" type="String">

      <column name="Key"/>

    </property>

    <property name="OldValue" access="property" type="String">

      <column name="OldValue"/>

    </property>

    <property name="NewValue" access="property" type="String">

      <column name="NewValue"/>

    </property>

    <many-to-one name="Journal" access="property" class="Company.Project.Libraries.Data.Store.Journal, Company.Project.Libraries.Data.Store" column="JournalId" lazy="proxy" />

  </class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-16"?>

<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">

  <class name="Company.Project.Libraries.Data.Store.Bar, Company.Project.Libraries.Data.Store" table="Bars">

    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">

      <generator class="native">

      </generator>

    </id>

    <bag name="Journals" access="property" table="Journals" lazy="false" cascade="all-delete-orphan">

      <key column="JournalableId" />

      <one-to-many class="Company.Project.Libraries.Data.Store.Journal, Company.Project.Libraries.Data.Store" />

    </bag>

  </class>

</hibernate-mapping>

Reply via email to