I have a DateTime field in my database. I am using hibernate
and spring mvc
framework. I am able to insert DateTime field.If I update the DateTimeFiled then hour, min and seconds are set to zero.
Here is my code:
java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
String formattedDate = cd.getStartTimeFrom();
System.out.println("input for dao date is "+formattedDate);
Date tmp= new Date();
try {
tmp= sdf1.parse(formattedDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder registry = new ServiceRegistryBuilder();
registry.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
SessionFactory sessionFactory =
configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
session.beginTransaction();
Query query=session.createQuery("update FeedFile set
priority=:priority, startTime=:startTime where id=:id");
query.setInteger("id", cd.getId());
query.setDate("startTime",tmp);
System.out.println("---- Priority : "+ cd.getPriority());
query.setInteger("priority", cd.getPriority());
modifications = query.executeUpdate();
session.getTransaction().commit();
If I have the record with value 2015-11-19 03:05:22
and if I update the date value using above code to 2015-11-25 09:06:12
then op is 2015-11-25 00:00:00