ComponentMap<> not working ?

Original Post Martin F's Avatar

Martin F

13 Mar, 2010 05:38 PM via web

Hello,

i am trying to map a component by following the example on http://wiki.fluentnhibernate.org/Fluent_mapping#Components under ComponentMap<>

But it keeps throwing an FluentNHibernate.Visitors.UnresolvedComponentReferenceVisitedException ("Visitor attempted on unresolved componented reference 'Password', referenced from property 'Password' of 'Member', unable to continue").

I Just have a PasswordMap class which inherits from ComponentMap and contains the Component Mappings and then i map it with Component(x => x.Password);

If i use the "old" way of mapping components it works fine.
I am using Build #629.

Anyone have an idea of what I could be doing wrong ?

Martin

Btw. when mapping with Component(x => x.TheComponent) it only exposes a ColumnPrefix method, it is missing the possibility to set Access, LazyLoad and so on (which is possible when you use the "old" way of mapping a component).

  1. Support Staff 2 Posted by James Gregory on 17 Mar, 2010 10:27 AM

    James Gregory's Avatar

    The ComponentMap functionality is still experimental, as you've discovered. I'd appreciate it if you could post a minimal solution to reproduce the issue, and I'll look into it. I've not had any issues using ComponentMap, so you must be doing something differently to how I am.

  2. 3 Posted by Martin on 17 Mar, 2010 02:59 PM

    Martin's Avatar

    Thanks for the reply.

    my PasswordMap class looks like the following

    internal class PasswordMap : ComponentMap<Password>
    {
        public PasswordMap()
        {
            Map(p => p.ChangedAt);
            Map(p => p.ResetCodeExpiresAt);
         }
    }
    

    My MemberMap class contains the following (please notice it is a SubClassMap)

    internal class MemberMap : SubclassMap<Member>
    {
        public MemberMap()
        {           
            Map(x => x.FirstName);
            Map(x => x.LastName);
            Map(x => x.Birthday);
            Map(x => x.Gender);
    
            References(x => x.Country);
    
            HasMany(x => x.Emails);
            HasMany(x => x.Addresses);
    
            Component(x => x.Password).ColumnPrefix("Password");
        }
    }
    

    If i map the "old" way it works fine, but using the ComponentMap it fails when creating the Session factory.

  3. Support Staff 4 Posted by James Gregory on 17 Mar, 2010 03:01 PM

    James Gregory's Avatar

    Great, thanks. I'll investigate it asap.

    It may be a conflict with SubclassMap, as I've not personally used the two
    together. Any chance you could run a test and see if you get the same
    behaviour from within a ClassMap?

  4. 5 Posted by Martin on 17 Mar, 2010 03:17 PM

    Martin's Avatar

    Thanks for the quick reply.

    Will try it out in a moment.
    Actually first really thought about it might be the problem when writting the reply :)

  5. 6 Posted by Martin on 17 Mar, 2010 03:35 PM

    Martin's Avatar

    Just tested it.

    It only throws an exception when using the SubclassMap, so I would assume it has something to do with that. :)

  6. Support Staff 7 Posted by James Gregory on 17 Mar, 2010 03:38 PM

    James Gregory's Avatar

    Great, well that makes my life a little easier. Thanks Martin, I'll look
    into this when I get home.

  7. 8 Posted by Martin on 25 Mar, 2010 02:28 PM

    Martin's Avatar

    Got home yet ? ;)

    Any idea of when you will merge Pauls latest changes/commits ? :)

    Also the source code downloaded from fluentnhibernate.org is missing the file "CombinedAssemblyTypeSource.cs" (which of course can easily be downloaded via GIT, but i thought it would be nice to mention it).

  8. 9 Posted by Daniel Tian on 14 Apr, 2010 04:23 AM

    Daniel Tian's Avatar

    Any update on this issue? I just ran into the same problem, where I have a SubclassMap and a Component inside it. I'm using the latest revision as of 4/13/2010.

  9. Support Staff 10 Posted by James Gregory on 30 Apr, 2010 08:37 AM

    James Gregory's Avatar

    If you try updating now there have been some bug fixes made on ComponentMap and SubclassMap use.

  10. 11 Posted by Daniel Tian on 01 May, 2010 01:36 AM

    Daniel Tian's Avatar

    Thanks James, the most recent trunk head solved the subclass mapping issue, but now I'm running into a new problem. One of my components contains another component:

    public class Agency
    {
        public string Name { get; set; }
        public Address Address { get; set; }
    }
    

    Both Agency and Address are components. In another entity class, I have a PrimaryAgency and a BackupAgency. I'm using automapping, and I expect to see these rows in the database table for the entity:

    PrimaryAgencyName
    PrimaryAgencyAddressStreet
    PrimaryAgencyAddressZip
    BackupAgencyName
    BackupAgencyAddressStreet
    BackupAgencyAddressZip
    

    Instead I get:

    PrimaryAgencyName
    BackupAgencyName
    AddressStreet
    AddressZip
    

    So it looks like it's picking up the column name from the root Agency component, but not for the Address component inside (it's mapping both addresses to the same column). When I try to save an instance of the entity, it throws an ArgumentOutOfRangeException, which makes me believe that Fluent's trying to look for the correct column name but can't find it since it was mapped wrong.

    Does this problem have anything to do with the commit message you wrote about nested-same-type components? I thought that meant that you can't nest an Agency inside an Agency, for example, but something like an Address inside an Agency should be fine.

  11. 12 Posted by Daniel Tian on 01 May, 2010 02:24 AM

    Daniel Tian's Avatar

    Also, the most recent build seems to have broke fluent component mapping so that this doesn't work anymore:

    Component(x => x.Agency);
    

    but this still does:

    Component(x => x.Agency, m =>
    {
        m.Map(x => x.Name);
    }
    

    It will throw a NullReferenceException when trying to build the Configuration object. Reverting back a previous version of Fluent NHib shows that this bug was introduced with the fixes to components in subclasses.

  12. Support Staff 13 Posted by James Gregory on 06 May, 2010 08:27 PM

    James Gregory's Avatar

    I've just committed some fixes that should hopefully stop you getting a NullReferenceException. Any updates would be helpful, if you get time to check out the new version.

  13. 14 Posted by Daniel Tian on 06 May, 2010 10:30 PM

    Daniel Tian's Avatar

    Hi James, thanks for the update. Because I switched over to using HBM mappings, I haven't had a chance to test whether the component mapping fails for fluent mappings. However, the issue I mentioned in post #11 with components inside components mapping incorrectly still exists for automapping. Also, overriding the mapping for a component throws a FluentConfigurationException: "Tried to add a component 'Agency' when already added".

    This is the code I'm using:

    public class AssessmentOverride : IAutoMappingOverride<Assessment>
    {
        public void Override(AutoMapping<Assessment> mapping)
        {
            mapping.Component(x => x.Agency);
        }
    }
    
  14. 15 Posted by Daniel Tian on 06 May, 2010 10:39 PM

    Daniel Tian's Avatar

    Ok, I just checked the fluent mappings with an older revision of my project. Seems like the NullReferenceException problem is fixed.

  15. Support Staff 16 Posted by James Gregory on 07 May, 2010 08:05 AM

    James Gregory's Avatar

    Just curious, did you test your automapper setup with the latest binary? I did make a fix for another support issue, #128, which was related to the automapper and the "already added" exception.

  16. 17 Posted by Daniel Tian on 07 May, 2010 08:12 AM

    Daniel Tian's Avatar

    I tested it with commit 12cc9f81a9fa31fdde47, which was the latest commit at the time of my previous post (gotta hate how there's no revision numbers). I noticed that the latest commit currently is the one where component overriding is fixed. I'll try it out later and let you know if it's been fixed.

  17. Support Staff 18 Posted by James Gregory on 07 May, 2010 08:18 AM

    James Gregory's Avatar

    Yeah, there's one commit after 12cc9f8, and that's the one with the fix for the "already added" exception.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Insert the next number in this sequence: 10, 11, 12, 13, 14, ??

    Recent Discussions

    05 Jul, 2010 10:29 PM
    05 Jul, 2010 12:45 PM
    05 Jul, 2010 12:42 PM
    05 Jul, 2010 12:17 PM
    05 Jul, 2010 12:12 PM

     

    03 Jul, 2010 12:26 AM
    02 Jul, 2010 02:17 PM
    02 Jul, 2010 08:18 AM
    02 Jul, 2010 12:20 AM
    01 Jul, 2010 10:14 PM