views:

328

answers:

1

I have a method that will return a list of suggested orders. If the user passes a null that criteria is ignored.

public IList<SuggestedOrderItem> GetSuggestedOrderItemByCriteria
        (
            int? itemNumber,
            int? deptNumber            
        )
    {
        try
        {
            NHibernate.ICriteria criteria = NHibernateSession.CreateCriteria(typeof(Core.SuggestedOrderItem));

            if (itemNumber.HasValue)
                criteria.CreateCriteria("Item", "Item").Add(Expression.Eq("Item.ItemNumber", itemNumber.Value));

            if (deptNumber.HasValue)
                criteria.CreateCriteria("Item.Department", "Department").Add(Expression.Eq("Department.DepartmentNumber", deptNumber.Value));

            return criteria.List<Core.SuggestedOrderItem>();
        }
        catch (NHibernate.HibernateException he)
        {
            DataAccessException dae = new DataAccessException("NHibernate Exception", he);
            throw dae;                
        }

    }

If I provide a criteria, everything works fine. By fine I mean it retrieves the correct suggested orders and they all have different version numbers. If all the criteria are null it retrieves all suggested orders as it should, however the version numbers are all the same. Another developer is working on the UI and he's calling the above method to populate a screen with all orders so the user can select one to modify. When I get his update request though I am refusing it as the version number does not match the actual version for the object. This is how the version column looks in the mapping file:

<version name="Version" type="Int64" generated="always" column="ORA_ROWSCN" access="property" unsaved-value="0"/>

Thank you very much for any assistance!

UPDATE:

I downloaded nhprof to see if the sql query being generated in each case was different. Regardless of if I pass no criteria or I do provide a criteria they are exactly the same except for a where clause. When I ran each of the queries in a db editor, I got the same results I was seeing from my service. Is this some kind of strange oracle issue? If I include a where clause I get different ora_rowscn numbers, otherwise they are all the same.

A: 

It turns there is some kind of issue when using ANSI Sql (I am hitting an oracle 10g db). I added the following property to my app.config to try to get nhibernate to not use ANSI:

<property name="use_outer_join">false</property>

However, this did not help. I then added:

<property name="max_fetch_depth">0</property>

There are now more db hits, but the version numbers are coming back as expected.

Justin Holbrook
I updated to NH2.1 which allowed me to use an oracle 10 dialect. I was able to remove the 2 properties above and since it's not generating ansi sql I'm not having the original issue mentioned.
Justin Holbrook