久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='0zVoM'></tfoot>

      <small id='0zVoM'></small><noframes id='0zVoM'>

      <legend id='0zVoM'><style id='0zVoM'><dir id='0zVoM'><q id='0zVoM'></q></dir></style></legend>
      1. <i id='0zVoM'><tr id='0zVoM'><dt id='0zVoM'><q id='0zVoM'><span id='0zVoM'><b id='0zVoM'><form id='0zVoM'><ins id='0zVoM'></ins><ul id='0zVoM'></ul><sub id='0zVoM'></sub></form><legend id='0zVoM'></legend><bdo id='0zVoM'><pre id='0zVoM'><center id='0zVoM'></center></pre></bdo></b><th id='0zVoM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0zVoM'><tfoot id='0zVoM'></tfoot><dl id='0zVoM'><fieldset id='0zVoM'></fieldset></dl></div>
          <bdo id='0zVoM'></bdo><ul id='0zVoM'></ul>
      2. JPA 自動 BigDecimal 轉換

        JPA automatic BigDecimal conversion(JPA 自動 BigDecimal 轉換)

          <tbody id='dTXgf'></tbody>

            • <bdo id='dTXgf'></bdo><ul id='dTXgf'></ul>

                <small id='dTXgf'></small><noframes id='dTXgf'>

              1. <legend id='dTXgf'><style id='dTXgf'><dir id='dTXgf'><q id='dTXgf'></q></dir></style></legend>
                <i id='dTXgf'><tr id='dTXgf'><dt id='dTXgf'><q id='dTXgf'><span id='dTXgf'><b id='dTXgf'><form id='dTXgf'><ins id='dTXgf'></ins><ul id='dTXgf'></ul><sub id='dTXgf'></sub></form><legend id='dTXgf'></legend><bdo id='dTXgf'><pre id='dTXgf'><center id='dTXgf'></center></pre></bdo></b><th id='dTXgf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dTXgf'><tfoot id='dTXgf'></tfoot><dl id='dTXgf'><fieldset id='dTXgf'></fieldset></dl></div>
                <tfoot id='dTXgf'></tfoot>
                  本文介紹了JPA 自動 BigDecimal 轉換的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我們正在使用 MyEclipse 生成我們的 jpa 訪問層.之后我們有了生成的模型和數據層訪問服務.我們遇到了一些具有定義精度的字段的問題.

                  We are generating our jpa access layers with MyEclipse. Afterwards we have the generated models and data layer access services. We ran into some problems for some fields with a defined precision.

                  實體:

                  @Entity
                  public class TestEntity{
                     @Column(name="DECTEST", scale = 3, precision = 13)
                     BigDecimal decTest;
                  
                  }
                  

                  現在我們創建一個 bean 并嘗試保存它:

                  Now we create a bean and try to save it:

                  TestEntity te = new TestEntity();
                  te.setDecTest(new BigDecimal(1.2));
                  
                  TestEntityService.save(te);
                  

                  我們收到以下錯誤:原因:com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][t4][1037][11190] BigDecimal 轉換期間發生異常.詳見附件 Throwable.

                  We get the following error: Caused by: com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][t4][1037][11190] Exception occurred during BigDecimal conversion. See attached Throwable for details.

                  Caused by: com.ibm.db2.jcc.a.a: [ibm][db2][jcc][converters][608][10994] Overflow occurred during numeric data type conversion of "1.1999999999999999555910790149937383830547332763671875".
                  at com.ibm.db2.jcc.a.e.a(e.java:61)
                  at com.ibm.db2.jcc.b.jb.a(jb.java:1772)
                  ... 73 more
                  

                  問題似乎是我們的 BigDecimals 規模高于數據庫中的規模.

                  The problem seems to be that our BigDecimals scale is higher then the one from the database.

                  一個可行的解決方法是:

                  A working workaround is:

                  TestEntity te = new TestEntity();
                  
                  BigDecimal decTest = new BigDecimal(1.2);
                  
                  te.setDecTest(decTest.setScale(3,RoundingMode.HALF_UP);
                  
                  TestEntityService.save(te);
                  

                  通過這種解決方法,我們手動將 BigDecimals 精度降低到數據庫中的一個.

                  With this workaround we reduce the BigDecimals precicsion manually to the one of the database.

                  但是,如果數據模型發生變化,我們將不得不手動調整比例.有沒有辦法讓我們的 jpa/hibernate 實現自動為我們進行轉換?例如.設置屬性.在創建 bean 的地方做這件事無論如何都是錯誤的.

                  However if the data model changes we would have to adjust the scale there manually. Is there a way to get our jpa / hibernate implementation to do that conversion for us automatically? E.g. with setting a property. Doing it at the spot where one is creating the bean would be the wrong spot to do it anyways.

                  推薦答案

                  您可以使用自定義用戶類型,也可以像這樣簡單地實現屬性的 setter:

                  You could use a custom user type, or you could simply implement the setter of the property like this:

                  public void setDecTest(BigDecimal decTest) {
                      this.decTest = decTest.setScale(3, RoundingMode.HALF_UP));
                  }
                  

                  因此,這種舍入將被封裝在實體中.

                  This rounding would thus be encapsulated in the entity.

                  請注意,使用 double 來初始化 BigDecimal 有點奇怪.如果您希望將 1.2 存儲在 BigDecimal 中,請使用 new BigDecimal("1.2"),您將不會使用 1.19999999999999999555910790149937383830547332763671875 初始化 BigDecimal代碼>.

                  Note that using a double to initialize a BigDecimal is a bit strange. If you want 1.2 to be stored in the BigDecimal, use new BigDecimal("1.2"), and you won't have a BigDecimal initialized with 1.1999999999999999555910790149937383830547332763671875.

                  這篇關于JPA 自動 BigDecimal 轉換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <bdo id='hntD3'></bdo><ul id='hntD3'></ul>
                      <tbody id='hntD3'></tbody>
                    • <tfoot id='hntD3'></tfoot>

                      <small id='hntD3'></small><noframes id='hntD3'>

                        <i id='hntD3'><tr id='hntD3'><dt id='hntD3'><q id='hntD3'><span id='hntD3'><b id='hntD3'><form id='hntD3'><ins id='hntD3'></ins><ul id='hntD3'></ul><sub id='hntD3'></sub></form><legend id='hntD3'></legend><bdo id='hntD3'><pre id='hntD3'><center id='hntD3'></center></pre></bdo></b><th id='hntD3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hntD3'><tfoot id='hntD3'></tfoot><dl id='hntD3'><fieldset id='hntD3'></fieldset></dl></div>
                        1. <legend id='hntD3'><style id='hntD3'><dir id='hntD3'><q id='hntD3'></q></dir></style></legend>
                            主站蜘蛛池模板: 色一级片| 草b视频 | 中文字幕 在线观看 | 九九伦理电影 | 999久久久久久久久6666 | 日韩精品在线播放 | 欧美一区二区在线观看 | 日韩精品免费 | 黑人精品欧美一区二区蜜桃 | 91精品一区二区三区久久久久久 | 91在线色视频 | 在线看亚洲 | 粉嫩粉嫩芽的虎白女18在线视频 | av黄色在线播放 | 亚洲综合国产精品 | 久久亚洲精品国产精品紫薇 | 国产精品国产三级国产aⅴ浪潮 | 国产精品久久久久久久久久三级 | 精品99爱视频在线观看 | 影音先锋中文字幕在线观看 | 国产成人高清 | 亚洲一区二区三区免费在线观看 | 欧美一区二区三区视频 | 三级国产三级在线 | 亚洲一区二区不卡在线观看 | 自拍偷拍亚洲视频 | a在线观看 | 欧美精品一区二区三区四区五区 | www精品美女久久久tv | 亚洲一二三区精品 | 成人精品免费视频 | 91精品免费 | 久久99精品久久久久久青青日本 | 国产精品国产三级国产播12软件 | 成人欧美一区二区三区在线播放 | 国产精品日韩一区二区 | 无码一区二区三区视频 | 黄色电影在线免费观看 | 日日干日日操 | 久久精品16 | 亚洲人人舔人人 |