Mapped property can't be found...

mikael's Avatar

mikael

13 Aug, 2010 07:09 PM via web

i,

I might have found a bug but am unsure if it is a fluent bug or a nhibernate bug but the nhibernate guys are mean and scary so I try here first. For some reason mappings are generated for two properties but when they are accessed I get an exception saying they don't exist. I am NOT using the xml mapping below but they are generated every time I build i don't know any way to show you the real mappings.


  <column name="deleted_at" not-null="false" />
</property>
<property name="DeletedBy" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  <column name="deleted_by" length="25" not-null="false" />
</property>

When the property is accessed I get the following exception:
could not resolve property: DeletedAt of: FakturaLight.Invoice

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.QueryException: could not resolve property: DeletedAt of: Invoice

Source Error:

Line 203: public void DeleteInvoice(int id)
Line 204: {
Line 205: var invoice = Work.CurrentSession.QueryOver()
Line 206: .Where(x => x.Id == id)
Line 207: .And(x => x.DeletedAt == null)

The actual class looks like:

[MetadataType(typeof (InvoiceMetadata))]
public class Invoice : EntityBase
{
    private decimal _invoiceTotal;
    private decimal _kmTotal;
    private decimal _productTotal;
    private decimal _workdayTotal;

    public Invoice()
    {
        Products = new List<Product>();
        Workdays = new List<Workday>();
    }

    public virtual DateTime? DeletedAt { get; set; }
    public virtual string DeletedBy { get; set; }
    public virtual DateTime StartDate { get; set; }
    public virtual DateTime EndDate { get; set; }
    public virtual string Period { get; set; }
    public virtual string InvoicePrefix { get; set; }
    public virtual int InvoiceNumber { get; set; }
    public virtual int Km { get; set; }
    public virtual decimal KmPrice { get; set; }
    public virtual decimal HourPrice { get; set; }
    public virtual short GST { get; set; }
    public virtual bool Printed { get; set; }
    public virtual int CustomerId { get; set; }
    public virtual Company Company { get; set; }
    public virtual ICollection<Product> Products { get; private set; }
    public virtual ICollection<Workday> Workdays { get; private set; }
}

public class InvoiceMapping : ClassMap<Invoice>
{
    public InvoiceMapping()
    {
        Id(x => x.Id)
            .GeneratedBy.Identity()
            .UniqueKey("ix_invoice_id_prefix_number");

        Map(x => x.InvoiceNumber)
            .UniqueKey("ix_invoice_id_prefix_number");
        Map(x => x.InvoicePrefix)
            .Not.Nullable()
            .UniqueKey("ix_invoice_id_prefix_number");

        Map(x => x.StartDate);
        Map(x => x.EndDate);
        Map(x => x.Period);
        Map(x => x.Km);
        Map(x => x.KmPrice);
        Map(x => x.HourPrice);
        Map(x => x.GST);
        Map(x => x.CustomerId);
        Map(x => x.Printed);

        References(x => x.Company)
            .Column("company_id");
        HasMany(x => x.Workdays)
            .KeyColumn("invoice_id");
        HasMany(x => x.Products)
            .KeyColumn("invoice_id");

        Map(x => x.CreatedAt)
            .Nullable();
        Map(x => x.CreatedBy)
            .Nullable()
            .Length(25);
        Map(x => x.UpdatedAt)
            .Nullable();
        Map(x => x.UpdatedBy)
            .Nullable()
            .Length(25);
        Map(x => x.DeletedAt)
            .Nullable();
        Map(x => x.DeletedBy)
            .Column("deleted_by")
            .Nullable()
            .Length(25);
    }
}

I can't spot anything wrong but when I try to generate schema (both for update and drop/export) it doesn't generate those two columns. I am clueless...

  1. 2 Posted by mikael on 14 Aug, 2010 11:34 AM

    mikael's Avatar

    Ok, this is definitely a fluent nhibernate issue. Fluent NHibernate generates the mappings for the columns but they are not passed on to NHibernate. When I run with log4net level ALL for logger NHibernate I get the following:

    < 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"
        mutable = "true"
        name = "Invoice,  Version=1.0.0.1, Culture=neutral, PublicKeyToken=null"
        table = "`invoice´" > 
    
        <id name = "Id" type= "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <column name = "invoice_id" / >
            <generator class = "identity" / >
        </id>
        <bag cascade="save-update" inverse="true" name="Workdays" mutable="true">
            <key foreign-key="fk_invoice_workday"><column name="invoice_id" / ></key>
            <one-to-many class="Workday,  Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" / > 
        </bag>
        <bag cascade="save-update" inverse="true" name="Products" mutable="true">
            <key foreign-key="fk_invoice_product"><column name="invoice_id" / ></key>
            <one-to-many class="Product,  Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" / >
        </bag>
        <property name="CreatedAt" type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="created_at" not-null="false" / >
        </property>
        <property name="CreatedBy" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="created_by" length="25" not-null="false" / > 
        </property>
        <property name="UpdatedAt" type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="updated_at" not-null="false" / >
        </property>
        <property name="UpdatedBy" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="updated_by" length="25" not-null="false" / >
        </property>
        <property name="InvoiceNumber" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="invoice_number" / >
        </property>
        <property name="InvoicePrefix" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <column name="invoice_prefix" not-null="true" / >
        </property>
        <property name="StartDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="start_date" / >
        </property>
        <property name="EndDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="end_date" / >
        </property>
        <property name="Period" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="period" / >
        </property>
        <property name="Km" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="km" / >
        </property>
        <property name="KmPrice" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="km_price" / >
        </property>
        <property name="HourPrice" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="hour_price" / >
        </property>
        <property name="GST" type="System.Int16, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="gst" / ></property>
        <property name="CustomerId" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="customer_id" / > </property>
        <property name="Printed" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="printed" / >
        </property>
        <many-to-one cascade="none" class="Company,  Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" foreign-key="fk_company_invoice" name="Company">
        <column name="company_id" / > 
        </many-to-one>
    </class > 
    </hibernate-mapping>

    So there is some issue here :(

  2. 3 Posted by mikael on 14 Aug, 2010 11:39 AM

    mikael's Avatar

    The following is also logged. I have no friggin idea why this happens. Could someone please enlighten me?

    Could it be .NET that is caching a previous version somewhere? I deleted the bin/obj folders and cleaned the tmp. Ran a build with clean and then a rebuild. But maybe I need to clean something else?

    13:24:34.903 [18] INFO  NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
    13:24:34.903 [18] INFO  NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: Invoice -> invoice
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Id -> invoice_id, type: Int32
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Workdays, type: System.Collections.Generic.IList`1[[Workday, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null]](Invoice.Workdays)
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Products, type: System.Collections.Generic.IList`1[[Product, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null]](Invoice.Products)
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: CreatedAt -> created_at, type: DateTime
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: CreatedBy -> created_by, type: String
    13:24:34.904 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: UpdatedAt -> updated_at, type: DateTime
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: UpdatedBy -> updated_by, type: String
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: InvoiceNumber -> invoice_number, type: Int32
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: InvoicePrefix -> invoice_prefix, type: String
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: StartDate -> start_date, type: DateTime
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: EndDate -> end_date, type: DateTime
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Period -> period, type: String
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Km -> km, type: Int32
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: KmPrice -> km_price, type: Decimal
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: HourPrice -> hour_price, type: Decimal
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: GST -> gst, type: Int16
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: CustomerId -> customer_id, type: Int32
    13:24:34.905 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Printed -> printed, type: Boolean
    13:24:34.913 [18] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Company -> company_id, type: Company
  3. 4 Posted by mikael on 14 Aug, 2010 02:35 PM

    mikael's Avatar

    Ok guys you have a bug to take care of! :) I am currently running in XML mode...

    The thing is that the mappings are outputted to disk ok (ExportTo(path)) but they are not sent to nhibernate ok. DeletedAt / DeletedBy are missing.

  4. Support Staff 5 Posted by James Gregory on 14 Aug, 2010 05:26 PM

    James Gregory's Avatar

    Mikael, thanks for the investion/report. I'm away from the computer right now, but I'll take a look the next chance I get.

  5. 6 Posted by mikael on 14 Aug, 2010 06:33 PM

    mikael's Avatar

    Happy birthday mate!

    Was not expecting a reply since it's your quarter of a century day :)

    Mikael Henriksson

    Tel: +46 (0) 730- 393 200
    ***@zoolutions.se

    On Sat, Aug 14, 2010 at 7:28 PM, James Gregory <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  6. 7 Posted by mikael on 30 Aug, 2010 06:26 PM

    mikael's Avatar

    Don't want to be a bother but any news on this?
    I had to skip fluent and use xml!

  7. Support Staff 8 Posted by Paul Batum on 25 Sep, 2010 10:54 PM

    Paul Batum's Avatar

    Hi Mikael,

    I am catching up on my much neglected pile of FNH related emails. Did you
    find a resolution for this at all? Are you still using an xml file? Also, if
    you are still on a xml file, are you using a hand written xml file? Did you
    try exporting the FNH xml file and using that?

    Paul.

    On Mon, Aug 30, 2010 at 1:28 PM, mikael <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  8. 9 Posted by mikael on 26 Sep, 2010 02:16 PM

    mikael's Avatar

    Hi,

    I still have that issue and am still using XML. As I think I stated
    somewhere the XML generated to disk works but the actual in memory version
    seems to be missing the property. Since I had to convert to xml I got rid of
    all the unneeded stuff that FNH generates but it's pretty much the same
    file.

    Mikael Henriksson

    Tel: +46 (0) 730- 393 200
    ***@zoolutions.se

    On Sun, Sep 26, 2010 at 12:56 AM, Paul Batum <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  9. Support Staff 10 Posted by Paul Batum on 26 Sep, 2010 03:17 PM

    Paul Batum's Avatar

    Hi Mikael,

    I've had another look at the code and I just can't see anything that might
    be causing us to drop some properties from the xml. If its written to disk,
    it really should be passed to NH. If you have built FNH from source you
    could stick breakpoints on lines 279 and 288 of PersistenceModel.cs as this
    is where we add the mapping documents to NH, and then you could check the
    xml right before its passed in. Assuming the properties are in that XML, the
    question will be why NH is ignoring them...

    Paul.

    On Sun, Sep 26, 2010 at 9:18 AM, mikael <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the opposite of north?