You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/08/15 19:14:27 UTC
svn commit: r1514382 - in /isis/site/trunk/content:
components/objectstores/jdo/about.md
components/objectstores/jdo/mapping-bigdecimals.md documentation.md
Author: danhaywood
Date: Thu Aug 15 17:14:27 2013
New Revision: 1514382
URL: http://svn.apache.org/r1514382
Log:
notes on mapping bigdecimals
Added:
isis/site/trunk/content/components/objectstores/jdo/mapping-bigdecimals.md
Modified:
isis/site/trunk/content/components/objectstores/jdo/about.md
isis/site/trunk/content/documentation.md
Modified: isis/site/trunk/content/components/objectstores/jdo/about.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/about.md?rev=1514382&r1=1514381&r2=1514382&view=diff
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/about.md (original)
+++ isis/site/trunk/content/components/objectstores/jdo/about.md Thu Aug 15 17:14:27 2013
@@ -16,6 +16,7 @@ The DataNucleus objectstore enables the
##### JDO Mapping Hints
- [Mapping Mandatory and Optional Properties](mapping-mandatory-and-optional-properties.html)
- [Mapping JODA Dates](mapping-joda-dates.html)
+- [Mapping BigDecimals](mapping-bigdecimals.html)
- [Mapping Blobs](components/objectstores/jdo/mapping-blobs.html)
- [Lazy Loading](lazy-loading.html)
- [Managed 1:m bidirectional relationships](managed-1-to-m-relationships.html)
Added: isis/site/trunk/content/components/objectstores/jdo/mapping-bigdecimals.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/mapping-bigdecimals.md?rev=1514382&view=auto
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/mapping-bigdecimals.md (added)
+++ isis/site/trunk/content/components/objectstores/jdo/mapping-bigdecimals.md Thu Aug 15 17:14:27 2013
@@ -0,0 +1,40 @@
+Title: Mapping BigDecimals
+
+Working with `java.math.BigDecimal` properties takes a little care due to scale/precision issues. This is certainly the case for HSQL, and (may be the case ) for all other RDBMS' too.
+
+For example, suppose we have:
+
+ private BigDecimal impact;
+
+ public BigDecimal getImpact() {
+ return impact;
+ }
+ public void setImpact(final BigDecimal impact) {
+ this.impact = impact;
+ }
+
+JDO/DataNucleus creates, at least with HSQL, the table with the field type as NUMERIC(19). No decimal digits are admitted. (Further details [here](http://hsqldb.org/doc/2.0/guide/sqlgeneral-chapt.html#sgc_numeric_types)).
+
+What this implies is that, when a record is inserted, a log entry similar to this one appears:
+
+ INSERT INTO ENTITY(..., IMPACT, ....) VALUES (...., 0.5, ....)
+
+But when that same record is retrieved, the log will show that a value of "0" is returned, instead of 0.5.
+
+The solution is to explicitly add the scale to the field like this:
+
+ @javax.jdo.annotations.Column(scale=2)
+ private BigDecimal impact;
+
+ public BigDecimal getImpact() {
+ return impact;
+ }
+ public void setImpact(final BigDecimal impact) {
+ this.impact = impact;
+ }
+
+
+In addition, you should also set the scale of the `BigDecimal`, using `setScale(scale, roundingMode)`. More information can be found [here](http://www.opentaps.org/docs/index.php/How_to_Use_Java_BigDecimal:_A_Tutorial) and [here](http://www.tutorialspoint.com/java/math/bigdecimal_setscale_rm_roundingmode.htm).
+
+
+
Modified: isis/site/trunk/content/documentation.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/documentation.md?rev=1514382&r1=1514381&r2=1514382&view=diff
==============================================================================
--- isis/site/trunk/content/documentation.md (original)
+++ isis/site/trunk/content/documentation.md Thu Aug 15 17:14:27 2013
@@ -200,6 +200,7 @@ Note: this viewer is third-party open so
##### JDO Mapping Hints
- [Mapping Mandatory and Optional Properties](components/objectstores/jdo/mapping-mandatory-and-optional-properties.html)
- [Mapping JODA Dates](components/objectstores/jdo/mapping-joda-dates.html)
+- [Mapping BigDecimals](components/objectstores/jdo/mapping-bigdecimals.html)
- [Mapping Blobs](components/objectstores/jdo/mapping-blobs.html)
- [Lazy Loading](components/objectstores/jdo/lazy-loading.html)
- [Managed 1:m bidirectional relationships](components/objectstores/jdo/managed-1-to-m-relationships.html)