Description

Any application or portlet dealing with currencies should really use the java BigDecimal class. It would be nice and fairly trivial for the ServiceBuilder to support this.

I've just done a quick and dirty test and all I needed to do was use type="java.math.BigDecimal" in my service.xml and then modify the ext-hbm.xml to have type="big_decimal" in the appropriate place
(This was with postgresql).

Surely there are other people out there working with currencies within the liferay system that could
benefit as well.

Background: I'm writing a very specialised shopping basket system which is very loosely based on the
Liferay's shopping basket and I've just realised that I shouldn't be using double values and that
it might not be very appropriate for Liferay's shopping basket portlet either (I haven't analysed in detail
how it does its rounding).

Marcel Jansen
added a comment - 06/Jun/06 2:27 PM FYI
It definitely works (combination of "java.math.BigDecimal" and "big_decimal"). Use of
org.apache.commons.validator.routines.CurrencyValidator has also been very useful.

Reinaldo Silva
added a comment - 04/Nov/10 11:48 AM Patch and FTL service builder templates overrides to make it work on:
Liferay 6.1.X (rev. 65274)
PostgreSQL 8.4 (should work on Mysql too, but not tested)
Also the following args must be added to "build-common-plugin.xml" SDK:
<target name="build-service">
<java
classname="com.liferay.portal.tools.servicebuilder.ServiceBuilder"
classpathref="service.classpath"
>
<arg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
...
<!-- HERE YOUR OVERRIDES -->
<arg value="-Dservice.tpl.hbm_xml=<your_plugin_package_path>/hbm_xml.ftl" />
<arg value="-Dservice.tpl.persistence_impl=<your_plugin_package_path>/persistence_impl.ftl" />
<arg value="-Dservice.tpl.model=<your_plugin_package_path>/model.ftl" />
<arg value="-Dservice.tpl.model_impl=<your_plugin_package_path>/model_impl.ftl" />
<arg value="-Dservice.tpl.model_clp=<your_plugin_package_path>/model_clp.ftl" />
<arg value="-Dservice.tpl.service_clp_serializer=<your_plugin_package_path>/service_clp_serializer.ftl" />
</java>
...
</target>
The database used is NUMERIC and it can be NULL, circunventing the NULL to ZERO default behavior of Liferay numeric fields.
Only issue is that you must explicitly declare the "type='text'" attribute on "<aui:input />" elements to show properly when the field has no value, besides that all work properly.
Also, not tested on special columns (PKs, FKs).