Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db2: Eclipselink creates table with Db2 data type DOUBLE instead of REAL for a Java float #2282

Open
mswatosh opened this issue Oct 15, 2024 · 1 comment

Comments

@mswatosh
Copy link
Member

For an entity with Java float attributes, using jakarta.persistence.schema-generation.database.action results in columns being created as Double (64-bit precision) instead of Real (32-bit precision). This is due to Eclipselink attempting to create the column as Float instead of Real:
CREATE TABLE Packages (ID INTEGER NOT NULL, DESCRIPTION VARCHAR(255), HEIGHT FLOAT, LENGTH FLOAT, WIDTH FLOAT, PRIMARY KEY (ID))

This results in the following:

                                Data type                     Column
Column name                     schema    Data type name      Length     Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID                              SYSIBM    INTEGER                      4     0 No    
DESCRIPTION                     SYSIBM    VARCHAR                    255     0 Yes   
HEIGHT                          SYSIBM    DOUBLE                       8     0 Yes   
LENGTH                          SYSIBM    DOUBLE                       8     0 Yes   
WIDTH                           SYSIBM    DOUBLE                       8     0 Yes   

persistence.xml

<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>

Package.java

@Entity
@Table(name = "Packages")
public class Package {

    public String description;

    @Id
    public int id;

    public float height;

    public float length;

    public float width;

The end result of this is the first time an entity is persisted on a db2 connection, the float values can be slightly off due to the precision change from 32 bit to 64 bit. This can result in incorrect sorting like this issue: #2194

@mswatosh
Copy link
Member Author

I'm not sure if this is the only place, but essentially:

https://github.com/eclipse-ee4j/eclipselink/blob/ec0c9cdda67c6e88813a78ce4b2b3e3968fef15c/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/platform/database/DB2Platform.java#L314C10-L314C84

        fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT", false));
        fieldTypeMapping.put(Double.class, new FieldTypeDefinition("FLOAT", false));

should be

        fieldTypeMapping.put(Float.class, new FieldTypeDefinition("REAL", false));
        fieldTypeMapping.put(Double.class, new FieldTypeDefinition("FLOAT", false));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant