java - Queried date value moves by 2 days -
i'm trying learn spring data , using jparepository try , query date objects database. however, every time query date, result 2 days ahead of expected value. time component seems correct; it's date wrong. thing is, looks happens if compile code on machine. doing in person's yields correct results. there things need @ this? appreciated.
db value: 2014-05-29 19:47:00.576
testrepo() below returns 2014-05-27 19:47:00.576 instead.
public void testrepo() { system.out.println(repo.findbyname("testdate").getvalue()); }
==========
@autowired private entitymanager em; public dateobject findbyname(string name) { stringbuffer sql = new stringbuffer(); sql.append("select * "); sql.append("from static_dates "); sql.append("where name = '" + name + "'"); query q = em.createnativequery(sql.tostring(), dateobject.class); list<dateobject> resultlist = q.getresultlist(); system.out.println(resultlist.get(0).getvalue()); return resultlist.get(0); }
=========
@entity @table(name = "static_dates") public class dateobject { @id @column(name = "name") private string name; @column(name = "description") private string description; @column(name = "value") private date value; public date getvalue() { return value; } public void setvalue(date value) { this.value = value; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } }
additionally, saving date values yields correct result. example, if invoke repo.save( ... ) , pass current system date, same value reflects in database. select calls seem incorrect.
this fixed updating ms sql driver v3.0 v4.0.
Comments
Post a Comment