'Java LocalTime value is not correct, when query is using hibernate
The question is when I save the value between "12:00 AM"~"8:15 AM" in DB, and query the data using hibernate, it will automatically adding 5 mins.
I have tried using hibernate nativeQuery, it is worked. The value is correct, but when I use Query, the value will be wrong (adding 5 mins when the time value is between "12:00 AM"~"8:15 AM")
My environment is using spring boot 2, hibernate 5 and java1.8 'st1' is the field of the DB(SQL server) saving the time value between "12:00 AM"~"8:15 AM" in type "time(7)"
@Entity
@Table(name="class")
@NamedQuery(name="Class.findAll", query="SELECT c FROM Class c")
public class Class extends BaseBean implements Serializable {
private static final long serialVersionUID = 1L;
...
private LocalTime st1;
private LocalTime st2;
private LocalTime st3;
...
}
DB part
@Transactional
public ClassInfoModel getClass(Integer classRef){
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("select c from Class c "
+ "join fetch c.subject s "
+ "join fetch c.refCampus ca "
+ "where c.classRef=:classRef");
query.setInteger("classRef", classRef);
List<com.bean.Class> result=query.getResultList();
return (com.bean.Class) (result.size()==0?null:result.get(0));
}
Solution 1:[1]
Finally, it seem to be jvm System.setProperty("user.timezone", "Asia/xxxx"); is not matched with hibernate jdbc timezone hibernate.jdbc.time_zone=Asia/xxxx; After align that, it seem to go back to normal, Thanks Ole V.V.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sumit Sharma |
