2009-12-16 1 views
2

Fluent NHibernate Mapping에서 Join과 Component를 함께 사용하면 "Property Exception에 대한 getter를 찾을 수 없습니다"가 throw됩니다. 이것은 내 C# 코드Fluent에서 Join과 Component를 함께 사용 NHibernate Mapping에서 "Property Exception에 대한 getter를 찾을 수 없습니다"throws

using FluentNHibernate.Mapping; 

namespace FnhTest { 
    public class CustomerMap : ClassMap<Customer> { 
     public CustomerMap() { 
      Id(x => x.Id).GeneratedBy.Identity(); 
      Map(x => x.Name); 

      Join("BillingInfo", m => 
           { 
            m.KeyColumn("CustomerId"); 
            m.Component(x => x.BillingInfo, c => 
                    { 
                     c.Map(y => y.AccountNumber); 
                     c.Map(y => y.Address); 
                    }); 
           }); 
     } 
    } 

    public class BillingInfo { 
     public virtual string AccountNumber { get; set; } 
     public virtual string Address { get; set; } 
    } 

    public class Customer { 
     public virtual int Id { get; set; } 
     public virtual string Name { get; set; } 

     public virtual BillingInfo BillingInfo { get; set; } 
    } 
} 

입니다 그리고 이것은 내 데이터베이스 구조 =입니다>

Customers: 
    Id (int) 
    Name (varchar 50) 
BillingInfo: 
    Id (int) 
    AccountNumber (varchar 50) 
    Address (varchar 50) 
    CustomerId (int) (Foriegn Key to the Customers Id) 

유창함 NHibernate에이 설정에 대한 올바른 매핑을 생성하지만 어떤 이유로이 오류를 던졌습니다. 매핑과 나는 모든 웹을 통해 검색하지만, 도움이 아무것도 찾을 수 없습니다했습니다

Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"> 
    <class xmlns="urn:nhibernate-mapping-2.2" name="FnhTest.Customer, FnhTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Customer`"> 
    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <column name="Id" /> 
     <generator class="identity" /> 
    </id> 
    <property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <column name="Name" /> 
    </property> 
    <join table="BillingInfo"> 
     <key> 
     <column name="CustomerId" /> 
     </key> 
     <component name="BillingInfo" insert="true" update="true" optimistic-lock="true"> 
     <property name="AccountNumber" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
      <column name="AccountNumber" /> 
     </property> 
     <property name="Address" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
      <column name="Address" /> 
     </property> 
     </component> 
    </join> 
    </class> 
</hibernate-mapping> 

Error:

TestCase 'M:FnhTest.Program.Main(System.String[])' 
failed: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. 

    * Database was not configured through Database method. 

    FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. 

     * Database was not configured through Database method. 
    ---> NHibernate.PropertyNotFoundException: Could not find a getter for property 'AccountNumber' in class 'FnhTest.Customer' 
    at NHibernate.Properties.BasicPropertyAccessor.GetGetter(Type type, String propertyName) 
    at NHibernate.Tuple.Component.PocoComponentTuplizer.BuildGetter(Component component, Property prop) 
    at NHibernate.Tuple.Component.AbstractComponentTuplizer..ctor(Component component) 
    at NHibernate.Tuple.Component.PocoComponentTuplizer..ctor(Component component) 
    at NHibernate.Tuple.Component.ComponentEntityModeToTuplizerMapping..ctor(Component component) 
    at NHibernate.Tuple.Component.ComponentMetamodel..ctor(Component component) 
    at NHibernate.Mapping.Component.BuildType() 
    at NHibernate.Mapping.Component.get_Type() 
    at NHibernate.Mapping.SimpleValue.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:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs(93,0): at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 
     --- End of inner exception stack trace --- 
    d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs(100,0): at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 
    D:\repositories\core\playground\minhajuddin\FnhTest\FnhTest\Program.cs(8,0): at FnhTest.Program.Main(String[] args) 

     * Database was not configured through Database method. 


0 passed, 1 failed, 0 skipped, took 6.46 seconds (Ad hoc). 

오류입니다 아래 감안할 때, 도움의 모든 종류의 것 대단히 감사합니다 :)

EDIT : 글쎄, 나는이 일을하는 방법을 찾지 못했습니다 NHibernate, 나는 우리입니다 답변으로 Torkel이 게시 한 것이 무엇이든간에. 그러나 그것은 내 의도가 아니었다. 어쨌든.

답변

2

BillingInfo는 나에게 구성 요소가 아니라 엔티티처럼 보입니다.

BillingInfo를 엔티티로 매핑하면이를 고객으로 매핑하여 매핑 할 수 있습니다. 당신이 BillingInfo 이드하지만 고객 ID에에 참여하지 않음으로 속성 - 심판 importand됩니다

<many-to-one name="BillingInfo" property-ref="CustomerId" cascade="none"/> 

이 그러나 당신의 BillingInfo 클래스에 고객 ID 속성을 추가해야합니다.

+0

그래, 내가 할 수있는 고객이있을 때 항상 BillingInfo 객체가 필요 하겠지만, 이것이 일대일 매핑으로 할 수 있다는 것을 알고있다.하지만이 방법을 선호한다. 이 경우에는 '외부 조인' –

+0

제대로 설계하지 않으면 제대로 작동하지 않습니다. Torkel의 충고는 건전합니다. –

+0

Torkel이 말하는 것은 무엇이든 동의하지만, NHibernate에서 같은 것을 할 수있을 때, 왜 Fluent NHibernate에서 가능하지 않은지 궁금합니다. –

0

멍청한 관찰이라면 용서해주세요.하지만 BillingInfo에 Id 회원이 필요하지 않습니까?

+0

내 BillingInfo 클래스에 ID 필드가 있지만 NHibernate에 의해 채워지지 않았기 때문에 일종의 중복입니다. –

관련 문제