Vlad Mihalcea (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWUyYWY2Y2Fm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYW...
) HHH-13987 (
https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYW...
) LocalDate is affected by timezone conversions (
https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYW...
)
Change By: Vlad Mihalcea (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
If we set the default MySQL time zone to UTC:
{code:java}
default_time_zone='+00:00'
{code}
And use the following mapping:
{code:java}
@Entity(name = "UserAccount")
@Table(name = "user_account")
public static class UserAccount {
@Id
private Long id;
@Column(name = "first_name", length = 50)
private String firstName;
@Column(name = "last_name", length = 50)
private String lastName;
@Column(name = "subscribed_on")
private LocalDate subscribedOn;
public Long getId() {
return id;
}
public UserAccount setId(Long id) {
this.id = id;
return this;
}
public String getFirstName() {
return firstName;
}
public UserAccount setFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public String getLastName() {
return lastName;
}
public UserAccount setLastName(String lastName) {
this.lastName = lastName;
return this;
}
public LocalDate getSubscribedOn() {
return subscribedOn;
}
public UserAccount setSubscribedOn(LocalDate subscribedOn) {
this.subscribedOn = subscribedOn;
return this;
}
}
{code}
When persisting the following entity:
{code:java}
UserAccount user = new UserAccount()
.setId(1L)
.setFirstName("Vlad")
.setLastName("Mihalcea")
.setSubscribedOn(
LocalDate.of(
2013, 9, 29
)
);
entityManager.persist(user);
{code}
Hibernate generates the following SQL INSERT statement:
insert into user_account (first_name, last_name, subscribed_on, id) values (?, ?, ?,
?)"], Params: \ [(Vlad, Mihalcea, 2013-09-29, 1)
However, when fetching it:
{code:java}
assertEquals(
LocalDate.of(
2013, 9, 29
),
userAccount.getSubscribedOn()
);
{code}
We get the following failure message:
{code:java}
Expected :2013-09-29
Actual :2013-09-28
{code}
This is because in the database the following row was inserted:
{code:java}
| id | first_name | last_name | subscribed_on |
|----|------------|-----------|---------------|
| 1 | Vlad | Mihalcea | 28-09-13 |
{code}
Setting the timezone property does not fix also emulates the problem even if the server
timezone is not set :
{code:java}
@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(AvailableSettings.JDBC_TIME_ZONE, "UTC");
}
{code}
because this is I think java.sql.Date and LocalDate should not taken into consideration be
affected by `LocalDateType` timezone conversions as they shouldn’t behave like Timestamp
types that contain time information.
(
https://hibernate.atlassian.net/browse/HHH-13987#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13987#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:29f7b81 )