I noticed a peculiar behavior with NHibernate.
Context:
I have a table with a composite key (a number, a string and a date) and a few other columns. I noticed that a query on this table (hibernate class) was significantly slower than queries on other tables. even though there is only one record (hibernate object) returned.
Observation:
- A surrogate key was introduced and mapped it as the primary key, running the query again resulted in the same performance as before for Object Hydration.
- Hydration of the object was 6-7 times faster if Queried on the surrogate key. 2.
In all the above query runs, database performance was consistent.
There are no Associations or relationships defined in the hibernate mapping of this table.
I am not able to explain the difference in performance of object hydration (populating the .Net Objects with data).
What can I do to tweak the code to be as performant as the query using the PK when I have to use another column in the criteria.
Thanks in Advance
Kiran
EDIT: Table structure.. I have put in the create table script itself.. as I was not able to format it properly..
CREATE TABLE “TEST”
(
“REFERENCE” VARCHAR2(5 BYTE) NOT NULL,
“PRIORITY” NUMBER(6,0) NOT NULL,
“EFF_FROM_DATE” DATE NOT NULL,
“EFF_TO_DATE” DATE NOT NULL,
“VALUE” VARCHAR2(100 BYTE) NOT NULL,
“LAST_UPDATE_USERNAME” VARCHAR2(30 BYTE) NOT NULL,
“LAST_UPDATE_DATE_TIME” DATE NOT NULL,
“NOTE_1” VARCHAR2(20 BYTE),
“NOTE_2” VARCHAR2(20 BYTE)
)
This discrepancy was solved by forcing nhibernate to use the Oracle driver instead of the Microsoft driver for oracle.
I followed steps from this blog
http://www.timvasil.com/blog14/category/Oracle.aspx