Advanced Database Persistence for Java Examples & Reference Manual |
The HotRod Oracle adapter automatically maps known database column types to DAO Java types. In most of the cases this default Java type is well suited to handle the database values. However, when needed the default Java type of a property can be overridden by a custom type if it's provided by the developer.
If a custom Java type is not specified HotRod will use the following rules to decide which Java type to use for each Oracle column. In yellow is the DAO property type. In parenthesis the actual object type returned by the Oracle JDBC driver, that on occasions may be different.
Please note that the Java types for the Oracle columns may vary depending on the specific version and variant of the RDBMS, the operating system where the database engine is running, and the JDBC driver version.
Oracle Column Type | Default Java Type |
---|---|
NUMBER(p,s), DECIMAL(p,s), DEC(p,s), NUMERIC(p,s), NUM(p,s) |
If neither p or s are specified:
|
SMALLINT, INTEGER, INT |
java.math.BigInteger Note: SMALLINT , INTEGER , and INT
are equivalent to NUMBER(38) . |
FLOAT(p) | if p is not specified (i.e. a 126-bit float):
|
REAL | java.math.BigDecimal Note: REAL is equivalent to FLOAT(63) . |
DOUBLE PRECISION | java.math.BigDecimal Note: DOUBLE PRECISION is equivalent to FLOAT(126) . |
BINARY_FLOAT | java.lang.Float |
BINARY_DOUBLE | java.lang.Double |
CHAR(n), VARCHAR(n), VARCHAR2(n), NCHAR(n), NVARCHAR2(n) |
java.lang.String |
CLOB, NCLOB |
java.lang.String * |
LONG | No default java type ** |
RAW(n), LONG RAW |
byte[] |
BLOB | byte[] * |
BFILE | No default java type ** |
DATE | java.util.Date |
TIMESTAMP | java.sql.Timestamp |
TIMESTAMP WITH TIME ZONE | java.sql.Timestamp |
TIMESTAMP WITH LOCAL TIME ZONE | java.sql.Timestamp |
ROWID | java.lang.String |
UROWID | java.lang.Object (oracle.sql.ROWID) |
XMLTYPE | No default java type ** |
URITYPE | java.lang.Object (oracle.sql.STRUCT) |
INTERVAL YEAR TO MONTH | java.lang.Object (oracle.sql.INTERVALYM) |
INTERVAL DAY TO SECOND | java.lang.Object (oracle.sql.INTERVALDS) |
VARRAY(n) | java.lang.Object (oracle.sql.ARRAY) |
STRUCT | java.lang.Object (oracle.sql.STRUCT) |
REF | java.lang.Object |
*
LOB
types are by default read all at once into memory as byte arrays. They
can also be read/written using streaming instead of loading them all
at once. To do this you’ll need to write a custom MyBatis
TypeHandler
.
** It may be possible to read/write from/to these columns using a
MyBatis custom
TypeHandler
. This is, however, not an out-of-the-box solution.
To override the default Java type see the reference section for the
tables, views, and selects. The Example 19 - Custom DAO
Property Java Types shows a case where a custom type overrides the
default type. To override the default type add a
<column>
tag in a
<table>
,
<view>
, or
<select>
definition.