Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8818983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:14:22+00:00 2026-06-14T05:14:22+00:00

I try to convert an Enum into a BigDecimal using the Converter of EclipseLink.

  • 0

I try to convert an Enum into a BigDecimal using the Converter of EclipseLink. The conversion works, but the resulting database column has a type of String. Is it possible to set a parameter, that EclipseLink builds a decimal column type within the database?

I use a class, which implements org.eclipse.persistence.mappings.converters.Converter.

The application server logs

The default table generator could not locate or convert a java type (null) into a database type for database field (xyz). The generator uses java.lang.String as default java type for the field.

This message is generated for every field, which uses a converter. How can I define a specific database type for these fields?

public enum IndirectCosts {

EXTENDED {
    public BigDecimal getPercent() {
        return new BigDecimal("25.0");
    }
},
NORMAL {
    public BigDecimal getPercent() {
        return new BigDecimal("12.0");
    }
},
NONE {
    public BigDecimal getPercent() {
        return new BigDecimal("0.0");
    }
};

public abstract BigDecimal getPercent();

public static IndirectCosts getType(BigDecimal percent) {
    for (IndirectCosts v : IndirectCosts.values()) {
        if (v.getPercent().compareTo(percent) == 0) {
            return v;
        }
    }
    throw new IllegalArgumentException();
}
}

The database has to store the numeric values. I use such a converter:

public class IndirectCostsConverter implements Converter {

@Override
public Object convertObjectValueToDataValue(Object objectValue, Session session) {
    if (objectValue == null) {
        return objectValue;
    } else if (objectValue instanceof IndirectCosts) {
        return ((IndirectCosts) objectValue).getPercent();
    }
    throw new TypeMismatchException(objectValue, IndirectCosts.class);
}

@Override
public Object convertDataValueToObjectValue(Object dataValue, Session session) {
    if (dataValue == null) {
        return dataValue;
    } else if (dataValue instanceof String) {
        return IndirectCosts.getType(new BigDecimal((String) dataValue));
    }
    throw new TypeMismatchException(dataValue, BigDecimal.class);
}

@Override
public boolean isMutable() {
    return false;
}

@Override
public void initialize(DatabaseMapping databaseMapping, Session session) {
}
}

Within convertDataValueToObjectValue(Object I have to use String because the SQL generator defines the database column as varchar(255). I would like to have decimal(15,2) or something.

Thanks a lot
Andre

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:14:23+00:00Added an answer on June 14, 2026 at 5:14 am

    The EclipseLink Converter interface defines a initialize(DatabaseMapping mapping, Session session); method that you can use to set the type to use for the field. Someone else posted an example showing how to get the field from the mapping here: Using UUID with EclipseLink and PostgreSQL

    The DatabaseField’s columnDefinition, if set, will be the only thing used to define the type for DDL generation, so set it carefully. The other settings (not null, nullable etc) will only be used if the columnDefinition is left unset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java you can try to convert any String value to Integer, but when
My problem is the following. I try to convert a string into double. In
I'm using Lyx to produce a Latex document, and when i try to convert
I try to convert cs file to DLL file .. when I am using
I try to convert keystrokes into chracters. In other question someone recommand to use
I try to convert a string into a date in t-sql. However get results
I try to convert a div tag into something I can drag and drop
When i try to convert my list JSON serializer coverts a list into string
I try to convert a unsigned long into a character string, appending a comma
I try to convert a sjis string to utf-8 using the iconv API. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.