hibernate配备保存2位小数
hibernate配置保存2位小数
类:
生成表结构为:
ps:
Oracle使用标准、可变长度的内部格式来存储数字。这个内部格式精度可以高达38位。
NUMBER数据类型可以有两个限定符,如:
java对象类型是:BigDecimal 配置文件字段类型:big_decimal
precision表示数字中的有效位。如果没有指定precision的话,Oracle将使用38作为精度。
scale表示数字小数点右边的位数,scale默认设置为0. 如果把scale设成负数,Oracle将把该数字取舍到小数点左边的指定位数。
类:
public class Account { private Integer accountId; //账户id private BigDecimal accountMoney; //账户总金额 private BigDecimal accountLockMoney;//锁定金额 private Date accountCreateDate; //创建时间配置文件:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.anycall.bean"> <class name="Account" table="tuan_account"> <id name="accountId" column="tuan_account_id" length="50" type="integer"> <generator class="sequence"> <param name="sequence">seq_tuan_normal</param> </generator> </id> <property name="accountMoney" column="tuan_account_money" length="200" not-null="true" type="big_decimal" scale="2"/> <property name="accountLockMoney" column="tuan_account_lock_money" length="20" not-null="true" type="big_decimal" scale="2" /> <property name="accountCreateDate" column="tuan_account_create_date" length="20" not-null="true" type="timestamp"/> <many-to-one name="person" column="tuan_account_person_id" not-null="true"/> </class> </hibernate-mapping>
生成表结构为:
SQL> desc tuan_account; Name Type Nullable Default Comments ------------------------ ------------ -------- ------- -------- TUAN_ACCOUNT_ID NUMBER(10) TUAN_ACCOUNT_MONEY NUMBE(19,2) TUAN_ACCOUNT_LOCK_MONEY NUMBER(19,2) TUAN_ACCOUNT_CREATE_DATE DATE SQL>
ps:
Oracle使用标准、可变长度的内部格式来存储数字。这个内部格式精度可以高达38位。
NUMBER数据类型可以有两个限定符,如:
java对象类型是:BigDecimal 配置文件字段类型:big_decimal
precision表示数字中的有效位。如果没有指定precision的话,Oracle将使用38作为精度。
scale表示数字小数点右边的位数,scale默认设置为0. 如果把scale设成负数,Oracle将把该数字取舍到小数点左边的指定位数。