0

while updating datetime field using new Date() function, it having date part but it time part will be (00.00.00), Insertion it does,t have any problem 2013-08-02 12:57:09 ,but in updation it works like 2013-08-02 00:00:00....

session.createQuery(
"update DeviceDetails u set u.statusUpDate=:statusUpDate where u.id=:dID")
.setDate("statusUpDate", new Date())
.setInteger("dID",dID).executeUpdate();

session.getTransaction().commit()
1

1 Answer 1

3

Use setTimestamp(), and not setDate().

Or don't use a query at all: get the entity using Session.get(), and modify its fields.

Sign up to request clarification or add additional context in comments.

5 Comments

Why are you repeating the code you already have in your question in this comment?
I am really interest to know the difference between setDate(),setTimestamp().
setDate() uses a java.sql.Date (which doesn't have a time portion), whereas setTimestamp() uses a java.sql.Timestamp (which has a time portion). Read the javadoc of those two classes to know the exact difference.
AM using hibernate query to save the date and time...It working perfectly on saving the session object checkAdd.setcheck(newDate()); session.save(checkAdd); session.getTransaction().commit(); Once using update it working with date part not in time part... Actually the problem solved by using setTimestamp() function.Is the mentioned problem occurs because of the java library file
The problem occurs because you're using setDate(), which means: set the value of the parameter with this date without time value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.