【问题标题】:Fluent Hibernate Mapping hitch - passing wrong column name for subclassFluent Hibernate Mapping hitch - 为子类传递错误的列名
【发布时间】:2011-06-22 10:26:22
【问题描述】:

我完成了夏天的休眠屏幕投射,并试图将其转换为流利的,只是为了知识。

我有两个班(很简单)

public class Customer { ... }
public class PreferredCustomer : Customer { ... }

这些遵循table per sub class策略,所以流畅的映射是这样的:

CustomerMap - 
  //nothing related to PreferredCustomer - the spec says not required
public class PreferredCustomerMap : SubclassMap<PreferredCustomer>
{
    Map(x => x.CustomerSince);
    Map(x => x.OrderDiscountRate);
}

就是这样。 我的测试失败了,经过检查,它抱怨sql找不到列customer_id

这是hibernate产生的sql:

SELECT  customer0_.CustomerId as CustomerId1_0_, 
   customer0_.Version as Version1_0_, 
   customer0_.Firstname as Firstname1_0_, 
   customer0_.Lastname as Lastname1_0_, 
   customer0_1_.CustomerSince as Customer2_2_0_, 
   customer0_1_.OrderDiscountRate as OrderDis3_2_0_, 
       //here, customer0_1_.customer_id needs to be CustomerID really.
   case when customer0_1_.Customer_id is not null then 1 when customer0_.CustomerId is not null then 0 end as clazz_0_ 
    FROM [Customer] customer0_ left outer join [PreferredCustomer] customer0_1_ on customer0_.CustomerId=customer0_1_.Customerid 
    WHERE customer0_.Customer_Id=1

它显然只在 PreferredCustomer 加入表上这样做。找不到需要做的事情。

有什么想法吗?

编辑:我如何阅读 fluent 生成的 xml?这可能是一个好的开始。

【问题讨论】:

    标签: nhibernate fluent-nhibernate


    【解决方案1】:

    您需要在 SubclassMaps 中调用KeyColumn("CustomerID");

    【讨论】:

    • 我只是查看了配置文件并发现了这一点!来这里编辑我的问题并看到你的答案。我认为这应该在 wiki 的 first project 页面中提及。谢谢
    猜你喜欢
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2011-06-10
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多