Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:53:57+00:00 2026-05-26T17:53:57+00:00

I’m having trouble with a query where I select records within a given timespan.

  • 0

I’m having trouble with a query where I select records within a given
timespan.

The column I’m selecting from is of type DATE. I have mapped this
column as a DateTime property, and the query works but is slow.

The generated query looks like: (provided by NHProfiler)

select kifkalende0_.KALENDER_MEDARBEJDER_ID as KALENDER1_119_0_,
   kifkalende1_.KALENDER_EMNE_ID        as KALENDER1_210_1_,
   kifkalende0_.OPDATERET_TIDSPUNKT     as OPDATERET2_119_0_,
   kifkalende0_.AENDRET                 as AENDRET119_0_,
   kifkalende0_.OPDATERET_AF            as OPDATERET4_119_0_,
   kifkalende0_.OPRETTET_AF             as OPRETTET5_119_0_,
   kifkalende0_.OPRETTET_TIDSPUNKT      as OPRETTET6_119_0_,
   kifkalende0_.SLETTET                 as SLETTET119_0_,
   kifkalende0_.KALENDER_EMNE_ID        as KALENDER8_119_0_,
   kifkalende0_.MEDARBEJDER_ID          as MEDARBEJ9_119_0_,
   kifkalende1_.OPDATERET_TIDSPUNKT     as OPDATERET2_210_1_,
   kifkalende1_.BESKRIVELSE             as BESKRIVE3_210_1_,
   kifkalende1_.DATO                    as DATO210_1_,
   kifkalende1_.ER_FRA_SAG              as ER5_210_1_,
   kifkalende1_.FRA_SAG_ID              as FRA6_210_1_,
   kifkalende1_.FRA_TABEL               as FRA7_210_1_,
   kifkalende1_.FRA_TID                 as FRA8_210_1_,
   kifkalende1_.OPDATERET_AF            as OPDATERET9_210_1_,
   kifkalende1_.OPRETTET_AF             as OPRETTET10_210_1_,
   kifkalende1_.OPRETTET_TIDSPUNKT      as OPRETTET11_210_1_,
   kifkalende1_.SAG_TYPE                as SAG12_210_1_,
   kifkalende1_.TIL_TID                 as TIL13_210_1_,
   kifkalende1_.YDERLIGERE_BESKRIVELSE  as YDERLIGERE14_210_1_,
   kifkalende1_.EMNE_ID                 as EMNE15_210_1_,
   kifkalende1_.PERSON_ID               as PERSON16_210_1_
from   "KIF_KALENDER_MEDARBEJDER" kifkalende0_
   left outer join "KIF_KALENDER_EMNE" kifkalende1_ on 
kifkalende0_.KALENDER_EMNE_ID = kifkalende1_.KALENDER_EMNE_ID,
   "KIF_KALENDER_EMNE" kifkalende2_
where  kifkalende0_.KALENDER_EMNE_ID = kifkalende2_.KALENDER_EMNE_ID
   and (kifkalende0_.MEDARBEJDER_ID in (7624 /* :p3 */,6226 
/* :p4 */,7382 /* :p5 */,5774 /* :p6 */, 5775 /* :p7 */,8259 
/* :p8 */,8218 /* :p9 */,9899 /* :p10 */, 6000 /* :p11 */,5779 
/* :p12 */,5780 /* :p13 */,5782 /* :p14 */, 5783 /* :p15 */,5784 
/* :p16 */,5785 /* :p17 */,5788 /* :p18 */, 5789 /* :p19 */,5790 
/* :p20 */,7341 /* :p21 */,8963 /* :p22 */, 10201 /* :p23 */,10388 
/* :p24 */))       
and kifkalende2_.DATO >= TIMESTAMP '2010-11-10 00:00:00.00' /* :p0 */
and kifkalende2_.DATO <= TIMESTAMP '2010-11-10 23:59:59.00' /* :p1 */
and (kifkalende0_.SLETTET = TIMESTAMP '1899-12-31 00:00:00.00' /* :p2 */
    or kifkalende0_.SLETTET is null);

And in our database, it takes around a 1500 ms to execute.

If we change the query manually to:

select kifkalende0_.KALENDER_MEDARBEJDER_ID as KALENDER1_119_0_,
   kifkalende1_.KALENDER_EMNE_ID        as KALENDER1_210_1_,
   kifkalende0_.OPDATERET_TIDSPUNKT     as OPDATERET2_119_0_,
   kifkalende0_.AENDRET                 as AENDRET119_0_,
   kifkalende0_.OPDATERET_AF            as OPDATERET4_119_0_,
   kifkalende0_.OPRETTET_AF             as OPRETTET5_119_0_,
   kifkalende0_.OPRETTET_TIDSPUNKT      as OPRETTET6_119_0_,
   kifkalende0_.SLETTET                 as SLETTET119_0_,
   kifkalende0_.KALENDER_EMNE_ID        as KALENDER8_119_0_,
   kifkalende0_.MEDARBEJDER_ID          as MEDARBEJ9_119_0_,
   kifkalende1_.OPDATERET_TIDSPUNKT     as OPDATERET2_210_1_,
   kifkalende1_.BESKRIVELSE             as BESKRIVE3_210_1_,
   kifkalende1_.DATO                    as DATO210_1_,
   kifkalende1_.ER_FRA_SAG              as ER5_210_1_,
   kifkalende1_.FRA_SAG_ID              as FRA6_210_1_,
   kifkalende1_.FRA_TABEL               as FRA7_210_1_,
   kifkalende1_.FRA_TID                 as FRA8_210_1_,
   kifkalende1_.OPDATERET_AF            as OPDATERET9_210_1_,
   kifkalende1_.OPRETTET_AF             as OPRETTET10_210_1_,
   kifkalende1_.OPRETTET_TIDSPUNKT      as OPRETTET11_210_1_,
   kifkalende1_.SAG_TYPE                as SAG12_210_1_,
   kifkalende1_.TIL_TID                 as TIL13_210_1_,
   kifkalende1_.YDERLIGERE_BESKRIVELSE  as YDERLIGERE14_210_1_,
   kifkalende1_.EMNE_ID                 as EMNE15_210_1_,
   kifkalende1_.PERSON_ID               as PERSON16_210_1_
from   "KIF_KALENDER_MEDARBEJDER" kifkalende0_
   left outer join "KIF_KALENDER_EMNE" kifkalende1_ on 
kifkalende0_.KALENDER_EMNE_ID = kifkalende1_.KALENDER_EMNE_ID,
   "KIF_KALENDER_EMNE" kifkalende2_
where  kifkalende0_.KALENDER_EMNE_ID = kifkalende2_.KALENDER_EMNE_ID
   and (kifkalende0_.MEDARBEJDER_ID in (7624 /* :p3 */,6226 
/* :p4 */,7382 /* :p5 */,5774 /* :p6 */, 5775 /* :p7 */,8259 
/* :p8 */,8218 /* :p9 */,9899 /* :p10 */, 6000 /* :p11 */,5779 
/* :p12 */,5780 /* :p13 */,5782 /* :p14 */, 5783 /* :p15 */,5784 
/* :p16 */,5785 /* :p17 */,5788 /* :p18 */, 5789 /* :p19 */,5790 
/* :p20 */,7341 /* :p21 */,8963 /* :p22 */, 10201 /* :p23 */,10388 
/* :p24 */))  
   and kifkalende2_.DATO>=to_date('10-11-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
   and kifkalende2_.DATO<=to_date('10-11-2010 23:59:59', 'DD-MM-YYYY HH24:MI:SS')
   and (kifkalende0_.SLETTET=to_date('31-12-1899 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
   or kifkalende0_.SLETTET is null);

it executes in about 50ms.

Is there any way to make NHibernate generate to_date instead of
timestamp for date comparisons??

I am bit confused as to how the RegisterDateTimeTypeMappings works in
the Oracle10gDialect, but I tried extending it, changing the method to

            protected override void RegisterDateTimeTypeMappings()
            {
                    RegisterColumnType(DbType.Date, "DATE");
                    //RegisterColumnType(DbType.DateTime, "TIMESTAMP(4)");
                    RegisterColumnType(DbType.DateTime, "DATE");
                    RegisterColumnType(DbType.Time, "TIMESTAMP(4)");
            }

but that did not help.

Our environment is:

  • .net (C#) 4.0
  • NHibernate 3.1.0, used primarily via Linq
  • ODP.Net 11.2.2.0 against an Oracle 11g

Do anyone have any suggestions?

Thanks,
./Daniel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:53:58+00:00Added an answer on May 26, 2026 at 5:53 pm

    I solved my problem and yours by overriding the following NHibernate Class.
    The NHProfiler will still display a TIMESTAMP value but the underlying parameter will be of type DATE – which will be indexable if your oracle column is also a DateTime.
    Hover your mouse over the parameters in NHProfiler to see what I mean – something like:
    :p0: TIMESTAMP – ‘2011-07-01 00:00:00.00’ Date
    instead of
    :p0: TIMESTAMP – ‘2011-07-01 00:00:00.00’ Timestamp.

    I’m also using Oracle 11g, C# .Net 4, Nhibernate 3.2.

    public class OracleDataClientDriver2 : OracleDataClientDriver
    {
        protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
        {
            switch (sqlType.DbType)
            {
                    //Timestamp columns not indexed by Oracle 11g date columns. - Use Date 
                case DbType.DateTime:
                    base.InitializeParameter(dbParam, name, SqlTypeFactory.Date);
                    break;
                default:
                    base.InitializeParameter(dbParam, name, sqlType);
                    break;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.