Using ZonedDateTimeAttributeConverter may cause performance issue for transactions

ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table during a transaction.

While working on physical inventory feature of stock management, we found a problem.

A physical inventory is a batch operation, there will be lots of inserts in a transaction.

We found that if the insert statement involves a zoned date time being converted to a time stamp, then hibernate will generate update statements for the whole table.

And that’ll make the whole transaction very very slow.

We found a work around for this, which is to use the hibernate-java8 lib instead of using a custom made converter. That solves the problem.

But I have not found out why ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table yet.

If you are still using ZonedDateTimeAttributeConverter, and if you have potentially large transactions, you may have the same problem.

You can run this test to reproduce the problem: https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java

I just looked through the code, looks like the converter is still used from openlmis-service-util.

You may want to test your large transactions and see if you have the same problem.

···

On Monday, March 20, 2017 at 6:16:06 PM UTC+8, pf...@thoughtworks.com wrote:

ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table during a transaction.

While working on physical inventory feature of stock management, we found a problem.

A physical inventory is a batch operation, there will be lots of inserts in a transaction.

We found that if the insert statement involves a zoned date time being converted to a time stamp, then hibernate will generate update statements for the whole table.

And that’ll make the whole transaction very very slow.

We found a work around for this, which is to use the hibernate-java8 lib instead of using a custom made converter. That solves the problem.

But I have not found out why ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table yet.

If you are still using ZonedDateTimeAttributeConverter, and if you have potentially large transactions, you may have the same problem.

You can run this test to reproduce the problem: https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java

I’ve created a ticket to track this:

  I would vote for just switching to the one from Hibernate - don't think we need a custom one.

Regards,

Paweł

···

https://openlmis.atlassian.net/browse/OLMIS-2155
On 20.03.2017 11:32, wrote:

pfcui@thoughtworks.com

      I just looked through the code, looks like the converter is still used from openlmis-service-util.
      You may want to test your large transactions and see if you have the same problem.
    On Monday, March 20, 2017 at 6:16:06 PM UTC+8, wrote:

  You received this message because you are subscribed to the Google Groups "OpenLMIS Dev" group.

  To unsubscribe from this group and stop receiving emails from it, send an email to openlmis-dev+unsubscribe@googlegroups.com.

  To post to this group, send email to openlmis-dev@googlegroups.com.

  To view this discussion on the web visit [https://groups.google.com/d/msgid/openlmis-dev/cd489614-07b5-4dd5-9407-8efcd588fded%40googlegroups.com](https://groups.google.com/d/msgid/openlmis-dev/cd489614-07b5-4dd5-9407-8efcd588fded%40googlegroups.com?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).


Paweł Gesek

    Technical Project Manager

      / +48 690 020 875

SolDevelo Sp. z o. o. [LLC]

     Office:  +48 58 782 45 40 / Fax:  +48 58 782 45 41  Al. Zwycięstwa 96/98  81-451, Gdynia

     [http://www.soldevelo.com](http://www.SolDevelo.com)

               Place of registration: Regional Court for the City of Gdansk            KRS: 0000332728, TAX ID: PL5862240331, REGON: 220828585,            Share capital: 60,000.00 PLN

pf...@thoughtworks.com

ZonedDateTimeAttributeConverte r makes hibernate generate update statements on whole table during a transaction.

        While working on physical inventory feature of stock management, we found a problem.
          A physical inventory is a batch operation, there will be lots of inserts in a transaction.
          We found that if the insert statement involves a zoned date time being converted to a time stamp, then **                  hibernate will generate update statements *for the whole table***.

And that’ll make the whole transaction ** very very slow**.

          We found a work around for this, which is to use the hibernate-java8 lib instead of using a custom made converter. That solves the problem.
          But I have not found out why ZonedDateTimeAttributeConverte              r makes hibernate generate update statements on whole table yet.

If you are still using ZonedDateTimeAttributeConverte r, and if you have potentially large transactions, ** you may have the same problem**.

            You can run this test to reproduce the problem: [https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java](https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java)

pgesek@soldevelo.com

I agree, Pawel.

And as a rule of thumb, we should always prefer standard libraries vs custom unless there is a super-compelling case for custom …

···

https://openlmis.atlassian.net/browse/OLMIS-2155
On 20.03.2017 11:32, wrote:

pfcui@thoughtworks.com

I just looked through the code, looks like the converter is still used from openlmis-service-util.

You may want to test your large transactions and see if you have the same problem.

On Monday, March 20, 2017 at 6:16:06 PM UTC+8, wrote:

You received this message because you are subscribed to the Google Groups “OpenLMIS Dev” group.

To unsubscribe from this group and stop receiving emails from it, send an email to
openlmis-dev+unsubscribe@googlegroups.com.

To post to this group, send email to
openlmis-dev@googlegroups.com.

To view this discussion on the web visit
https://groups.google.com/d/msgid/openlmis-dev/cd489614-07b5-4dd5-9407-8efcd588fded%40googlegroups.com
.

For more options, visit
https://groups.google.com/d/optout
.

pf...@thoughtworks.com

ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table during a transaction.

While working on physical inventory feature of stock management, we found a problem.

A physical inventory is a batch operation, there will be lots of inserts in a transaction.

We found that if the insert statement involves a zoned date time being converted to a time stamp, then hibernate will generate update statements for the whole table.

And that’ll make the whole transaction very very slow.

We found a work around for this, which is to use the hibernate-java8 lib instead of using a custom made converter. That solves the problem.

But I have not found out why ZonedDateTimeAttributeConverter makes hibernate generate update statements on whole table yet.

If you are still using ZonedDateTimeAttributeConverter, and if you have potentially large transactions, you may have the same problem.

You can run this test to reproduce the problem: https://github.com/cuipengfei/gs-accessing-data-jpa/blob/master/complete/src/test/java/hello/T1ServiceTest.java


Paweł Gesek

Technical Project Manager

/ +48 690 020 875

SolDevelo Sp. z o. o. [LLC]

Office: +48 58 782 45 40/ Fax: +48 58 782 45 41Al. Zwycięstwa 96/9881-451, Gdynia

http://www.soldevelo.com

Place of registration: Regional Court for the City of Gdansk KRS: 0000332728, TAX ID: PL5862240331, REGON: 220828585,Share capital: 60,000.00 PLN

pgesek@soldevelo.com

openlmis-dev+unsubscribe@googlegroups.com

openlmis-dev@googlegroups.com

https://groups.google.com/d/msgid/openlmis-dev/189ddd92-302c-7e2e-b603-e595c6908cba%40soldevelo.com

https://groups.google.com/d/optout