pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="mwgcyak" 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="m8e04cu" 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="mwyesgw" 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>
                            主站蜘蛛池模板: 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 耐热钢-耐磨钢-山东聚金合金钢铸造有限公司 | 仿清水混凝土_清水混凝土装修_施工_修饰_保护剂_修补_清水混凝土修复-德州忠岭建筑装饰工程 | 自进式锚杆-自钻式中空注浆锚杆-洛阳恒诺锚固锚杆生产厂家 | 除尘器布袋骨架,除尘器滤袋,除尘器骨架,电磁脉冲阀膜片,卸灰阀,螺旋输送机-泊头市天润环保机械设备有限公司 | 转子泵_凸轮泵_凸轮转子泵厂家-青岛罗德通用机械设备有限公司 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 造价工程师网,考试时间查询,报名入口信息-网站首页 | 识禅_对禅的了解,从这里开始| 常州律师事务所_常州律所_常州律师-江苏乐天律师事务所 | 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 球磨机,节能球磨机价格,水泥球磨机厂家,粉煤灰球磨机-吉宏机械制造有限公司 | 陕西安玻璃自动感应门-自动重叠门-磁悬浮平开门厂家【捷申达门业】 | 深圳公司注册-工商注册公司-千百顺代理记账公司 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 金属检测机_金属分离器_检针验针机_食品药品金属检探测仪器-广东善安科技 | 远程会诊系统-手术示教系统【林之硕】医院远程医疗平台 | 水稻烘干机,小麦烘干机,大豆烘干机,玉米烘干机,粮食烘干机_巩义市锦华粮食烘干机械制造有限公司 水环真空泵厂家,2bv真空泵,2be真空泵-淄博真空设备厂 | 洛阳网站建设_洛阳网站优化_网站建设平台_洛阳香河网络科技有限公司 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 执业药师报名时间,报考条件,考试时间-首页入口 | 南京交通事故律师-专打交通事故的南京律师 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 小型UV打印机-UV平板打印机-大型uv打印机-UV打印机源头厂家 |松普集团 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | 大型工业风扇_工业大风扇_大吊扇_厂房车间降温-合昌大风扇 | 天津电机维修|水泵维修-天津晟佳机电设备有限公司 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 塑木弯曲试验机_铜带拉伸强度试验机_拉压力测试台-倾技百科 | MTK核心板|MTK开发板|MTK模块|4G核心板|4G模块|5G核心板|5G模块|安卓核心板|安卓模块|高通核心板-深圳市新移科技有限公司 | 品牌设计_VI设计_电影海报设计_包装设计_LOGO设计-Bacross新越品牌顾问 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 粉碎机_塑料粉碎机_塑料破碎机厂家-星标机械 | 宠物店加盟_宠物连锁店_开宠物店-【派多格宠物】 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 步进_伺服_行星减速机,微型直流电机,大功率直流电机-淄博冠意传动机械 | 耐酸泵,耐腐蚀真空泵,耐酸真空泵-淄博华舜耐腐蚀真空泵有限公司 精密模具-双色注塑模具加工-深圳铭洋宇通 |