久久久久久久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>
                            主站蜘蛛池模板: 成人黄色电影在线观看 | 午夜视频免费在线观看 | 狠狠操狠狠干 | 亚洲 中文 欧美 日韩 在线观看 | 亚洲综合在线播放 | 欧美黄色一区 | 日本亚洲欧美 | 久久精品黄色 | 欧美日韩国产精品一区 | 黄色网址在线免费播放 | 国产精品不卡 | 欧美视频中文字幕 | 亚洲欧洲成人av每日更新 | 91视频电影 | 亚洲国产aⅴ精品一区二区 免费观看av | 精品欧美一区二区在线观看 | 中文字幕日韩欧美一区二区三区 | 日韩精品一区二区三区免费观看 | 久久久久综合 | 久久久久久久国产精品视频 | 国产一区二区三区免费观看视频 | 81精品国产乱码久久久久久 | 九色视频网| 免费精品久久久久久中文字幕 | 亚洲国产精品久久久久婷婷老年 | 国产一区二区三区四区五区3d | 国产精品免费看 | 国产精品福利在线 | 午夜精品久久久久久久 | 91久久久久久久久久久 | 精品在线视频播放 | 亚洲影视在线 | 理论片午午伦夜理片影院 | 狠狠躁躁夜夜躁波多野结依 | 一区二区三区亚洲 | 欧美日韩久久 | 国产午夜精品久久久 | 天天色天天色 | 在线观看成人精品 | 国产一区二区久久 | www亚洲一区 |