2009-03-12 13 views
0

これは私のFluent設定の問題か私の思考の中の何らかのロジックに問題があるかどうかはわかりません。流暢なnHibernateとJoinSubClasses

私は基本的に、私は2つの継承クラス、AuthorとBorrower(それはライブラリシステムです)を持つPersonクラスを持っています。私が持っているマッピングです。

public class PersonMap : ClassMap<Person> 
{ 
    public PersonMap() 
    { 
     Id(x => x.Id, "id"); 
     Map(x => x.Name, "name"); 

     // Subclasses 
     AddPart(new AuthorMap()); 
     AddPart(new BorrowerMap()); 
    } 
} 

public class AuthorMap : JoinedSubClassPart<Author> 
{ 
    public AuthorMap() : base("person_id") 
    { 
     Map(x => x.Country, "country"); 
     HasMany(x => x.Books).Cascade.All().WithKeyColumn("book_id"); 
    } 
} 

public class BorrowerMap : JoinedSubClassPart<Borrower> 
{ 
    public BorrowerMap() : base("person_id") 
    { 
     Map(x => x.UserName, "user_name"); 
     HasMany(x => x.Schedule).Cascade.SaveUpdate().WithKeyColumn("borrower_id"); 
    } 
} 

は今、私は、「著者a.Name BY ORDER FROM」HQLを実行する場合、それは私が明らかにちょうど作家のリストをしたいすべての者と借入人エンティティのリストを返します。私はこれをまっすぐに設定してください。

答えて

0

しようとするいくつかのこと:サブクラスマップのそれぞれにおいて

  • を、WithTableName("Author")
  • でテーブル名を設定するには、person_id各サブクラステーブルのキー列のですか?そうでない場合、例えばbase("person_id")
  • base("key column name")

を変更、私は以下のマッピングと非常に類似したクエリをテストした:

public class DigitalFreeSubscriptionMap : JoinedSubClassPart<DigitalFreeSubscription> 
{ 
    public DigitalFreeSubscriptionMap() 
     : base("DigitalFreeSubscriptions") 
    { 
     WithTableName("DigitalFreeSubscriptions"); 
     ... 

public class FreeSubscriptionMap : JoinedSubClassPart<FreeSubscription> 
{ 
    public FreeSubscriptionMap() 
     : base("FreeSubscriptions") 
    { 
     WithTableName("FreeSubscriptions"); 
     ... 

の両方がSubscriptionのサブクラスです。私がテストしたデータベースには、1700のDigitalFreeSubscriptionsがあり、100万を超えるFreeSubscripions(および他の種類のサブスクリプション)があります。 HQLクエリ "FROM DigitalFreeSubscripion"は1700件の結果を返しました。要求ごと

、SubscriptionMapのトップ:

public class SubscriptionMap : AuditableClassMap<Subscription> 
{ 
    public SubscriptionMap() 
    { 
     WithTable("Subscriptions"); 
     Id(x => x.Id, "Subscriptions"); 

     AddPart(new FreeSubscriptionMap()); 
     AddPart(new DigitalFreeSubscriptionMap()); 
     // More sublass mappings and then the field mappings