openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Bauer <>
Subject Re: Saving a double in prosgres
Date Thu, 10 Jun 2010 16:19:59 GMT

I did not find a DOUBLEUNSIGNED type supported for PostgreSQL, but could
have missed something.

This should provide what you are looking for though...

    @ElementColumn(name = "ELEMENT", columnDefinition="DECIMAL(10,
    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:

    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.


2010/6/10 Håkon Sagehaug <>

> 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]

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message