/**
* When the TZ and Time of a date column are not relevant, than explain to me,
* why the date ends up as 2013-10-14 in my database....
*
* Starting with
* INSERT INTO foobars(id, ref_date, taken_on) values (2, '2013-10-15', '2013-10-15 05:29:21');
*
* @throws SQLException
*/
@Test
public void update() throws SQLException {
final Session session = entityManager.unwrap(Session.class);
final DateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
this.entityManager.getTransaction().begin();
Foobar foobar = this.entityManager.find(Foobar.class, 2);
foobar.setSomeOtherColumn("blah");
this.entityManager.getTransaction().commit();
final int id = foobar.getId();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
ResultSet rs = connection.createStatement().executeQuery("Select ref_date from foobars where id = " + id);
rs.next();
Date date = rs.getDate(1);
Assert.assertEquals("2013-10-15", sf.format(date));
System.out.println(date);
}
});
}