My problem is exactly same as described in following post but it hasn't been answered and it's 4 years old post!!!
https://forum.hibernate.org/viewtopic.php?f=1&t=976655
In summary, I have table per class hierarchy inheritance and I am using formula in discriminator column. When I try to insert new record (Entity) the insert fails because the generated sql doe开发者_运维知识库sn't include the discriminator column.
Alternatively I could define another property that maps to the column and make discriminator's "insert" attribute to false. However I don't like this approach as it will force me to almost rewrite what formula was there for in the domain object.
I would really appreciate if anyone else has fixed this problem some better way.
<class name="Account" table="ACCOUNT" abstract ="true">
<discriminator column ="ACCOUNT_TY" type ="string" formula="(case when ACCOUNT_TY in ('CASHCARD','ORPHAN','BLACK','EXTERNAL', 'INTERNAL') then 'OTHER' else ACCOUNT_TY end)" />
<subclass name ="CreditCardAccount" extends ="Account" discriminator-value="PREPAY" dynamic-update="true" >
<subclass name ="OtherAccount" extends ="Account" discriminator-value="OTHER" dynamic-update="true">
<subclass name ="PostpayAccount" extends ="Account" discriminator-value="POSTPAY" dynamic-update="true">
For those wondering I got the answer in following thread
http://groups.google.com/group/nhusers/browse_frm/thread/3cbf9d9589b6d203
basically if you are using formula in discriminator column, you need to define another property and mark the discriminator 's attribute insert = "false"
class name="Account" table="ACCOUNT" abstract ="true">
<discriminator column ="ACCOUNT_TY" type ="string" formula="(case when ACCOUNT_TY in ('CASHCARD','ORPHAN','BLACK','EXTERNAL', 'INTERNAL') then 'OTHER' else ACCOUNT_TY end)" insert = "false" />
<property name = "AccountType" column = "ACCOUNT_TY" />
See if this post helps you out: http://nhibernate.info/blog/2010/05/15/not-so-hidden-gems-of-nhibernate-formula-discriminators.html
精彩评论