Data Type Mappings
Database.com has its own built-in list of data types optimized for building business applications. This section describes how the Database.com JPA provider maps Java data types to Database.com types and vice versa.
Mapping Java to Database.com Data Types
This table maps commonly used Java data types to data types in Database.com. It shows which Database.com data type is created when you use a Java data type. This table is intended as a quick reference for Java developers who are not familiar with data types in Database.com.
Some of the Database.com data types are created with length or precision constraints. The @Column
annotations in the Standard JPA Annotation column represent the default constraints that are implied for each data type. You don't have to add the @Column
standard JPA annotation when you add a Java field, but the field behaves as if they are present. You can add annotations if you want to modify the default constraints.
Java Data Type | Database.com Data Type | Standard JPA Annotation |
---|---|---|
boolean | Checkbox | N/A |
byte | Text (255) 1 | @Column(length=255) |
char | Text (255) | @Column(length=255) |
short | Number (6, 0)2 | @Column(precision=6, scale=0) |
int | Number (11, 0) | @Column(precision=11, scale=0) |
long | Number (18, 0) | @Column(precision=18, scale=0) |
double | Number (16, 2) | @Column(precision=16, scale=2) |
float | Number (16, 2) | @Column(precision=16, scale=2) |
Boolean | Checkbox | N/A |
Byte | Text (255) | @Column(length=255) |
Character | Text (255) | @Column(length=255) |
Short | Number (6, 0) | @Column(precision=6, scale=0) |
Integer | Number (11, 0) | @Column(precision=11, scale=0) |
Long | Number (18, 0) | @Column(precision=18, scale=0) |
Double | Number (16, 2) | @Column(precision=16, scale=2) |
Float | Number (16, 2) | @Column(precision=16, scale=2) |
String | Text (255) | @Column(length=fieldLength) |
java.util.Date | Date | @Temporal(TemporalType.DATE) |
Calendar | Date/Time | @Temporal(TemporalType.TIMESTAMP) |
GregorianCalendar | Date/Time | @Temporal(TemporalType.TIMESTAMP) |
BigInteger | Number (18, 0) | @Column(precision=18, scale=0) |
BigDecimal | Currency | @Column(precision=16, scale=2) |
byte[] | See Binary (Base64) Fields. | N/A |
String[] | Picklist (Multi-Select) for selected values | @Enumerated(EnumType.STRING) OR @Enumerated(EnumType.ORDINAL) |
enum | Picklist for available values | N/A |
URL | URL | N/A |
1 The number in parentheses represents the field length.
2 The values in parentheses represent the decimal precision and decimal scale for the number. Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 256.99 has a precision of 5 and a scale of 2.
Note: The sum of the precision and scale can't exceed 18. If it does, the precision is automatically reduced so that the sum satisfies that limit.
Mapping Database.com to Java Data Types
This table maps Database.com data types to Java data types. It shows which Java data types are allowed for each Java data type. Some Database.com data types can map to more than one Java data type. This table is intended as a quick reference for Java developers who are familiar with data types in Database.com and want to see how they map to data types in Java and JPA.
The table includes a column for the standard JPA annotation used for each data type.
Database.com Data Type | Java Data Type | Standard JPA Annotation |
---|---|---|
Auto Number |
|
N/A |
Formula | String | @Column(length = fieldLength) 1 |
Lookup Relationship | Matches class of referenced object | @ManyToOne |
Master-Detail Relationship | Matches class of referenced object | @ManyToOne |
Checkbox |
|
N/A |
Currency |
|
@Column(precision=16, scale=2) |
Date | java.util.Date | @Temporal(TemporalType.DATE) |
Date/Time |
|
@Temporal(TemporalType.TIMESTAMP) |
String | @Column(length = fieldLength) | |
Number |
|
@Column(precision = decimalPrecision, scale = decimalScale) 2 |
Percent |
|
@Column(precision = decimalPrecision, scale = decimalScale) |
Phone | String | @Column(length = fieldLength) |
Picklist | enum for available values String for selected value |
For available values: @Enumerated(EnumType.STRING) OR @Enumerated(EnumType.ORDINAL) |
Picklist (Multi-Select) | enum for available values String[] for selected values |
For available values: @Enumerated(EnumType.STRING) OR @Enumerated(EnumType.ORDINAL) |
Text |
|
@Column(length = fieldLength) |
Text Area | String | @Column(length = fieldLength) |
Text Area (Long) | Not currently supported | N/A |
Text Area (Rich) | Not currently supported | N/A |
URL | URL | @Basic |
1 The fieldLength variable represents the field length.
2 The decimalPrecision and decimalScale variables represent the decimal precision and decimal scale respectively for the number. Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 256.99 has a precision of 5 and a scale of 2.