English 中文(简体)
如何利用《自由标准》和《Oracle》及时开展工作?
原标题:What is better way to work with time, using Hibernate Criteria and Oracle?

I want to select entity by Time. I have Oracle DBMS with field type DATE which contain date and time. This is my code. How to select data by Time criteria?

Calendar timeCal = new GregorianCalendar(0,0,0,0,0,0);
Date     timeMin = timeCal.getTime();

timeCal.add(Calendar.HOUR_OF_DAY, 1);
Date     timeMax = timeCal.getTime();

if (minDate != null && maxDate != null)
    criteria.add(Restrictions.between("eventDate", minDate, maxDate));

if (onDate != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(onDate);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    criteria.add(Restrictions.between("eventDate", onDate, calendar.getTime()));
}

if(minTime!=null&&maxTime!=null){
    /*
      How to add Restriction on eventDate field, for time only?
      if minTime is 3:00 and maxTime is 16:00, must to return
      all rows having the time part of their eventDate between 
      3:00 and 16:00, regardless of the date part
    */
}
最佳回答

I find answer. Just need use sqlRestriction.

criteria.add(
    Restrictions.sqlRestriction(
        " NUMTODSINTERVAL(EVENT_DATE - TRUNC(EVENT_DATE),  DAY ) BETWEEN  NUMTODSINTERVAL (?, SECOND ) AND NUMTODSINTERVAL (?, SECOND )",
        new Object[] { secondsForBegin, secondsForEnd },
        new Type[]   { StandardBasicTypes.INTEGER, StandardBasicTypes.INTEGER }));
问题回答

www.un.org/spanish/ga/president 因此,你需要一个总部程序,而不是一个标准目标。 波尔图将研究类似的东西。

from  tableName
where eventDate between :minDate and :maxDate
  and 3600 * hour( eventDate ) + 60 * minute( eventDate ) + second( eventDate )
      between :minSeconds and :maxSeconds

贴上<代码>的:明秒钟和<代码>:最大秒钟参数的适当位置。 http://www.un.org/Depts/DGACM/index_chinese.htm

详情见rel=“nofollow”http://docs.jboss.org/hibernate/core/3.3/vis/en/html/queryhql.html

你们不得不使用QKQ限制来做到这一点,或者,更可取的是,你不得不自行实施《危机》,这将发布适当的限制。

使用<代码>org.hibernate.criterion.I similarExpression 舱位作为前身:如果它不使用PogreSQL dialect,那么它就会产生L.K.的表述,down(columnName)如?,在这种表述的理由是 Value.toString().toLowerCase(

您的标准应当产生如下内容:to_date(to_char(columnName, HH24:MI:SS ), HH24:MI:SS ) <?),在你的表述是你的最长时间的情况下。 (当然,在关键时间上采用类似标准)





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签