Just a bit more background.
My entity classes are autogenerated pojo's (from a json schema, not that it matters). I don't have a lot of control over the data types (I can have String, Long, Double, java.util.Date).
I use an orm.xml file to define the mapping but would like convention over configuration for the type mapping.
All my date related values are have second precision but since they are stored in a java,util.Date the default type mapping to oracle is TIMESTAMP(6), which is with micro-second precision.
I have managed to have EclipseLink create columns with oracle data type DATE by adding the following converter to my project:
@Converter(autoApply = true)
public class DateConverter implements AttributeConverter<java.util.Date, java.sql.Date> {
@Override
public java.sql.Date convertToDatabaseColumn(java.util.Date attribute) {
if (attribute == null) {
return null;
}
return new java.sql.Date(attribute.getTime());
}
@Override
public java.util.Date convertToEntityAttribute(java.sql.Date dbData) {
if (dbData == null) {
return null;
}
return dbData;
}
}
I got the clue by looking at the source code for OraclePlatform.buildFieldTypes() and was pleasantly surprised when I discovered that the converter was also taken into account when generating the schema.
But, it is a bit of a hack and my luck runs out if I want to map java.lang.Long to NUMBER(9), If I could live with NUMBER(10) I could create a similar converter with <Long, Integer> signature. So is there a different way to do it (that does not involve setting scale for all the fields)?
Best regards Jens