JPA BigDecimal scale difference between Oracle and DB2 [message #708411] |
Tue, 02 August 2011 19:40 |
|
Hi forum,
An entity with field of type BigDecimal, scale 2, is handled (fetched) differently between Oracle and DB2.
(...)
@Entity
@Table(name = "ENTITYNUMBER")
public class EntityNumber implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
@Column(name="BIGDEC", nullable = false, unique = false, scale = 2, precision = 10)
private BigDecimal bigdec;
public EntityNumber() {
super();
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public BigDecimal getBigdec() {
return this.bigdec;
}
public void setBigdec(BigDecimal number) {
this.bigdec = number;
}
}
An entity (row) with column BIGDEC=12 is fetched as "12.00" from DB2 and "12" from Oracle, where
"12.00" means BigDecimal with scale=2
"12" means BigDecimal with scale=0.
In DB2 schema, the database column is defined as DECIMAL(10,2),
in oracle schema, the database column defined as NUMBER(10,2),
both generated by eclipselink DDL generation.
So the scale is ignored in oracle.
I cannot decide which behavior is expected, but it should be identical. Is this a bug, am I missing a configuration, or a restriction in portability?
I am using eclipselink 2.1.1.
Thanks
Rolf
[Updated on: Tue, 02 August 2011 19:44] Report message to a moderator
|
|
|
|
Re: JPA BigDecimal scale difference between Oracle and DB2 [message #710189 is a reply to message #709185] |
Thu, 04 August 2011 19:46 |
|
Hello Chris,
thanks for your reply. No scale is lost, I jost expected that the JPA provider encapsulates/hides differences of jdbc drivers. You are right, the behavior is exactly what is returned by the jdbc driver - DB2 returns always the scale of the database column, Oracle cuts the scale to the minimum if applicable. I was not aware of the fact that the scale = 2 attribute in the @Column annotation is for DDL only, as this is not explicitly described in the JPA Spec.
So if we want to have e.g. values of Money which always has scale()=2, we may have to change to a class like "Money" and use eclipselink converters - or replace equals on BigDecimal with compareTo == 0.
I did not yet find anything about configuration of one of the jdbc drivers.
Regards
Rolf
[Updated on: Thu, 04 August 2011 21:50] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.48374 seconds