[hibernate-issues] [JIRA] (HHH-13987) LocalDate is affected by timezone conversions

Vlad Mihalcea (JIRA) jira at hibernate.atlassian.net
Tue Apr 28 12:46:55 EDT 2020


Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Af5e8c0d3-3aae-4bb4-a4e1-25463d60d232 ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 ) HHH-13987 ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 ) LocalDate is affected by timezone conversions ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 )

Change By: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Af5e8c0d3-3aae-4bb4-a4e1-25463d60d232 )

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=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13987#add-comment?atlOrigin=eyJpIjoiMWUyYWY2Y2FmZGNlNDcyNGJkY2ExZTI2M2FjYmE0YmEiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:29f7b81 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200428/2a510396/attachment.html 


More information about the hibernate-issues mailing list