Håkon,
I did not find a DOUBLEUNSIGNED type supported for PostgreSQL, but could
have missed something.
This should provide what you are looking for though...
@PersistentCollection
@ElementColumn(name = "ELEMENT", columnDefinition="DECIMAL(10,
6)",nullable=false)
private double[] doubleValues;
JPA/OpenJPA 2.0 provides standardized support for column definitions by
using @ElementCollection and @Column, but unlike @PersistentCollection,
@ElementCollection cannot be applied to an array. Instead, you'd need to
use a collection type.
If you are using OpenJPA 2.0 you could modify your code as follows:
@ElementCollection
@Column(columnDefinition="DECIMAL(10,6)",nullable=false)
private List<Double> doubleValues;
public void setDoubles(Double[] doubles) {
doubleValues = Arrays.asList(doubles);
}
public Double[] getDoubles() {
return (Double[])doubleValues.toArray();
}
Since List does not support primitive types, you'd also need to use the
Double object type. You could then modify your getter and setter to convert
to and from a primitive array. I didn't go that far, but it would be fairly
simple. In addition, if you need to maintain the order of the array in the
DB, use the @OrderColumn annotation. There is an OpenJPA version for JPA
1.0 apps and a standardized version in JPA 2.0, same annotation name,
different packages.
hth,
-Jeremy
2010/6/10 Håkon Sagehaug <[email protected]>
> Hi all,
>
> I've got a persitent collection in a entity looking like this
>
> @PersistentCollection
> double[] doubleValues;
>
> But when I store the values the, it's rounded up. So if I want to store
> the
> value 2.1999999999999993 in the database it's stored as 2.2. The driver I
> 'm
> using is postgresql-8.3-603.jdbc3.jar. Should I use another type in the
> entity or is there another solution. I guess it's this issue [1], I'm
> facing. I found that you could set column property like this
>
>
>
> @Column(columnDefinition="DOUBLEUNSIGNED",precision=10,scale=6,nullable=false)
>
> But hwo can I set hat on a persitent collection?
>
> cheers, Håkon
>
> [1]
>
> http://openjpa.apache.org/builds/latest/docs/manual/dbsupport_postgresql.html#dbsupport_postgresql_issues
>