[hibernate-issues] [JIRA] (HHH-13987) LocalDate does not use the `hibernate.jdbc.time_zone` setting so conversion issues can occur

Vlad Mihalcea (JIRA) jira at hibernate.atlassian.net
Tue Apr 28 09:23:37 EDT 2020


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

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 ) HHH-13987 ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 ) LocalDate does not use the `hibernate.jdbc.time_zone` setting so conversion issues can occur ( https://hibernate.atlassian.net/browse/HHH-13987?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 )

Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 28/Apr/2020 06:23 AM Priority: Major Reporter: 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:

default_time_zone= '+00:00'

And use the following mapping:

@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 ;
   }
}

When persisting the following entity:

UserAccount user = new UserAccount()
	.setId(1L)
	.setFirstName( "Vlad" )
	.setLastName( "Mihalcea" )
	.setSubscribedOn(
		LocalDate.of(
			2013, 9, 29
		)
	);

entityManager.persist(user);

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:

assertEquals(
	LocalDate.of(
		2013, 9, 29
	),
	userAccount.getSubscribedOn()
);

We get the following failure message:

Expected :2013-09-29
Actual   :2013-09-28

This is because in the database the following row was inserted:

| id | first_name | last_name | subscribed_on |
|----|------------|-----------|---------------|
| 1  | Vlad       | Mihalcea  | 28-09-13      |

Setting the timezone property does not fix the problem:

@Override
protected void additionalProperties(Properties properties) {
	properties.setProperty(AvailableSettings.JDBC_TIME_ZONE, "UTC" );
}

because this is not taken into consideration by `LocalDateType`.

( https://hibernate.atlassian.net/browse/HHH-13987#add-comment?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13987#add-comment?atlOrigin=eyJpIjoiODZiZTY1M2Q1MmRmNDgwYTljZjI2OTA5ZGE0OTg0YmUiLCJwIjoiaiJ9 )

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/1cd142fb/attachment.html 


More information about the hibernate-issues mailing list