Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ami.server.dto.stats.JukeboxStatsReportDTO" table="calliope_log_h
ibernate.jukebox_stats_report">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="jukeboxId" column="jukebox_id"/>
<property name="hardDiskId" column="hard_disk_id"/>
<property name="companyId" column="company_id"/>
<property name="contractId" column="contract_id"/>
<property name="timeStart" column="time_start" type="date"/>
<property name="timeEnd" column="time_end" type="date"/>
<property name="timeReceived" column="time_received" type="date"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL 4.1.14
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I have searched the forums for a resolution to my issue, but have not found a thread which is close enough . . . I am trying to create an HQL statement that will allow me to select rows from a table which match a certain date value. However, I want to query ONLY on the date value, not the time. The column in the database in which I am selecting on is the "timeReceived" property in the mapping above. The associated column in the database is defined as a datetime column.
Basically, I want to create a comparable HQL statement that will produced the same results as the following standard SQL statement:
"select count(*) from table tb
where date_format(tb.time_received, '%Y-%m-%d') = current_date();"
In place of current date, I may use a formatted date object in the correct format or the MySQL current_date() function.
Is it possible to use something like the Query.setDate() method and somehow tell the HQL statment that I want to use MySQL specific date formatting functions on the property/column?
I assume there is a fairly easy solution to this as it is a very common type of query.