Good morning,
I have an application written in Java and behind it an Oracle database. The mapping is done with Hibernate.
The fact is that I have a problem when I try to do an update on a table with a column of type Date.
I have a class called Primerascitas
that has an attribute of type Date and one of its records has a value of 23/05/2017 11:30
. What I want is to update that record and only change the time to establish it at 09:30. I have the following code:
Session sesion = = NewHibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
tx = sesion.beginTransaction();
Primerascitas p = new Primerascitas();
p = (Primerascitas) sesion.get(Primerascitas.class,id.get(0));
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String fecha = "23/05/2017 09:30";
p.setFecha(sdf.parse(fecha));
sesion.update(p);
tx.commit();
sesion.close();
This code does not throw an exception or fail but does not update the record in the database. However, if in addition to the time change also date, in this way:
String fecha = "24/05/2017 09:30";
p.setFecha(sdf.parse(fecha));
The registry updates it correctly in the database. I suppose then that in the first case it does not detect that the record has changed.
The kind of java I want to update with the attribute of type Date is this:
public class Primerascitas implements java.io.Serializable {
private int PIdprimeracita;
private Pacientespotenciales pacientespotenciales;
private Date fecha;
private String observaciones;
and this is the mapping file that I have: