Statement in HQL in hibhibernate the WHERE statement query list appears empty

Source: Internet
Author: User

1.java.sql.date and Java.util.Date

Java.sql.Date is inherited from Java.util.Date and assumes that dates1 (java.sql.Date) is assigned to Dates2 (java.util.Date)

Dates2=new java.sql.Date (Dates1.gettime ()) can be performed by the following conversions;

2. The difference between the methods in Preparestament Settimestamp () and setdate () and getdate (), Gettimestamp () in resultset:

Gettimestamp (), Settimestamp () will get/set "date + Time" in the database, or it can be said to be a timestamp

GetDate (), setDate () ignores time, only gets/sets the "date" in which



To encounter a problem like this

When hibernate is applied, the Qurey object Qurey

Problem:

Query Query =ses.createquery (HQL);
Query. setDate ("EndTime", Newdate ());
At this time, the new Date () is truncated for seconds.

Workaround:

Java code
Query Query =ses.createquery (HQL);
Query. Settimestamp ("EndTime", Newdate ());

Summary: 1. If the datetime type is displayed in the database, use query. Settimestamp("EndTime", newdate can be solved ()); This problem can be set time to hour and seconds

Statement in HQL in hibhibernate the WHERE statement query list appears empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.