|
When persisting a class, a persistence solution needs to know how to persist the types of each field in the class.
Clearly a persistence solution can only support a finite number of Java types. It cannot know how to persist
every possible type creatable. The JDO/JPA specifications define lists of types that are required to be supported by
all implementations of those specifications.
JDO uses terminology First-Class object (FCO) and Second-Class object (SCO)
to categorize how these types are treated by the JDO implementation. Lets just explain what these mean.
- FCO's are objects that have an identity in the datastore. They can be referred to. Examples of FCO's
are an instance of a user-supplied class that is persistence capable.
- SCO's are objects that do not have an identity in the datastore. They can't be referred to directly. They are
aggregated to an FCO object and can be stored as part of the FCO object. SCO object can also
contain FCO elements, like an FCO object has a SCO field of type Collection which contains FCO
objects elements. Examples of SCO's are a field of type Date, that is typically stored as part of the FCO
object.
If the type that you want to persist (as "SCO") is not listed below you can always add support for it via a JPOX plugin
using the User-Types Plugin guide.
JPOX currently supports objects that are PersistenceCapable as FCO. In addition it supports persisting
fields of Interface or java.lang.Object type as FCO (since these are just references to PersistenceCapable objects).
The table below shows the currently supported SCO in JPOX (along with their JDBC type and
default-fetch-group setting, whether they are queryable). It also shows the specifications which require support for
the particular Java type.
Please note that if your particular Java type is not listed below, it is possible for you
to add support for it using a JPOX extension.
It also shows whether a java type will be assigned a "proxy" object that allows detection of changes to the object.
This is needed for things like Collections where you may add/remove elements and JPOX needs to know of updates.
This use of a proxy will not affect your use of those types in any way.
Please note that this list gives all JDBC types available with the various RDBMS adapters. The jdbc type in bold
is the default type that will be used when "jdbc-type" is not specified in the MetaData (assuming that the
RDBMS supports that JDBC type, and if not then JPOX will choose one itself).
Some RDBMS adapters will only support some of these. The list will be improved in the future to add many more
possibilities of persisting Java types using other JDBC types.
| Java Type | Spec. | DFG? | Persistent? | Proxied? | Queryable | JDBC Type(s) |
|---|
| boolean |   |  |  |  |  | BIT, CHAR ('Y','N'), BOOLEAN, TINYINT, SMALLINT, NUMERIC | | byte |   |  |  |  |  | TINYINT, SMALLINT, NUMERIC | | char |   |  |  |  |  | CHAR, INTEGER, NUMERIC | | double |   |  |  |  |  | DOUBLE, DECIMAL, FLOAT | | float |   |  |  |  |  | FLOAT, REAL, DOUBLE, DECIMAL | | int |   |  |  |  |  | INTEGER, BIGINT, NUMERIC | | long |   |  |  |  |  | BIGINT, NUMERIC, DOUBLE, DECIMAL, INTEGER | | short |   |  |  |  |  | SMALLINT, INTEGER, NUMERIC | | boolean[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | byte[] |   |  |  |  | [8] | LONGVARBINARY, BLOB | | char[] |   |  |  |  | [8] | LONGVARBINARY, BLOB | | double[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | float[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | int[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | long[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | short[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Boolean |   |  |  |  |  | BIT, CHAR('Y','N'), BOOLEAN, TINYINT, SMALLINT | | java.lang.Byte |   |  |  |  |  | TINYINT, SMALLINT, NUMERIC | | java.lang.Character |   |  |  |  |  | CHAR, INTEGER, NUMERIC | | java.lang.Double |   |  |  |  |  | DOUBLE, DECIMAL, FLOAT | | java.lang.Float |   |  |  |  |  | FLOAT, REAL, DOUBLE, DECIMAL | | java.lang.Integer |   |  |  |  |  | INTEGER, BIGINT, NUMERIC | | java.lang.Long |   |  |  |  |  | BIGINT, NUMERIC, DOUBLE, DECIMAL, INTEGER | | java.lang.Short |   |  |  |  |  | SMALLINT, INTEGER, NUMERIC | | java.lang.Boolean[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Byte[] |   |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Character[] |   |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Double[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Float[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Integer[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Long[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Short[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.lang.Number |  |  |  |  |  | | | java.lang.Object |  |  |  |  | | LONGVARBINARY, BLOB | | java.lang.String |   |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.lang.String[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.math.BigDecimal |   |  |  |  |  | DECIMAL, NUMERIC | | java.math.BigInteger |   |  |  |  |  | NUMERIC, DECIMAL | | java.math.BigDecimal[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.math.BigInteger[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.sql.Date |   |  |  |  |  | DATE, TIMESTAMP | | java.sql.Time |   |  |  |  |  | TIME, TIMESTAMP | | java.sql.Timestamp |   |  |  |  |  | TIMESTAMP | | java.util.ArrayList |   |  |  |  |  | | | java.util.BitSet |  |  |  |  | | LONGVARBINARY, BLOB | | java.util.Calendar [5] |  |  |  |  | | INTEGER, VARCHAR, CHAR | | java.util.Collection |   |  |  |  |  | | | java.util.Currency |  |  |  |  |  | VARCHAR, CHAR | | java.util.Date |   |  |  |  |  | TIMESTAMP, DATE, CHAR, BIGINT | | java.util.Date[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.util.GregorianCalendar [4] |  |  |  |  | | INTEGER, VARCHAR, CHAR | | java.util.HashMap |   |  |  |  |  | | | java.util.HashSet |   |  |  |  |  | | | java.util.Hashtable |   |  |  |  |  | | | java.util.LinkedHashMap [9] |   |  |  |  |  | | | java.util.LinkedHashSet [10] |   |  |  |  |  | | | java.util.LinkedList |   |  |  |  |  | | | java.util.List |   |  |  |  |  | | | java.util.Locale |  |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.util.Locale[] |  |  |  |  | [8] | LONGVARBINARY, BLOB | | java.util.Map |   |  |  |  |  | | | java.util.Properties |  |  |  |  |  | | | java.util.PriorityQueue |  |  |  |  |  | | | java.util.Queue |  |  |  |  |  | | | java.util.Set |   |  |  |  |  | | | java.util.SortedMap [2] |  |  |  |  |  | | | java.util.SortedSet [1] |  |  |  |  |  | | | java.util.Stack |  |  |  |  |  | | | java.util.TimeZone |  |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.util.TreeMap [2] |  |  |  |  |  | | | java.util.TreeSet [1] |  |  |  |  |  | | | java.util.UUID |  |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.util.Vector |   |  |  |  |  | | | java.awt.Color [3] |  |  |  |  | | INTEGER | | java.awt.Point [4] |  |  |  |  | | INTEGER | | java.awt.image.BufferedImage [7] |  |  |  |  | | LONGVARBINARY, BLOB | | java.net.URI |  |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.net.URL |  |  |  |  |  | VARCHAR, CHAR, LONGVARCHAR, CLOB, BLOB, DATALINK, UNIQUEIDENTIFIER | | java.io.Serializable |   |  |  |  | | LONGVARBINARY, BLOB | | javax.jdo.spi.PersistenceCapable |  |  |  |  |  | [embedded] | | javax.jdo.spi.PersistenceCapable[] |  |  |  |  | [8] | | | java.lang.Enum [6] |  |  |  |  |  | LONGVARBINARY, BLOB, VARCHAR, INTEGER |
- [1] - java.util.SortedSet, java.util.TreeSet allow the specification of comparators
via the "comparator-name" JPOX extension MetaData element (within <collection>).
The headSet, tailSet, subSet methods are only supported when using cached collections.
- [2] - java.util.SortedMap, java.util.TreeMap allow the specification of comparators
via the "comparator-name" JPOX extension MetaData element (within <map>).
The headMap, tailMap, subMap methods are only supported when using cached containers.
- [3] - java.awt.Color - stored in 4 columns (red, green, blue, alpha). ColorSpace is not persisted.
- [4] - java.awt.Point - stored in 2 columns (x and y).
- [5] - java.util.Calendar - stored in 2 columns (milliseconds and timezone).
- [6] - java.lang.Enum - by default, serialized into one column. Storing in VARCHAR or INTEGER data types
is available via the "Java5" plugin. Queryable if stored in VARCHAR or INTEGER columns.
- [7] - java.awt.image.BufferedImage is stored using JPG image format
- [8] - Array types are queryable if not serialised, but stored to many rows
- [9] - java.util.LinkedHashMap is stored without ordering, hence as just a Map currently
- [10] - java.util.LinkedHashSet is stored without ordering, hence as just a Set currently
| Java Type | JDBC Type | Database | Additional Information |
|---|
| java.lang.String | DATALINK | DB2 | By default uses the SQL function: DLURLCOMPLETEONLY to fetch the column from database. This setting can
be overwritten by the select-function extension. See the MetaData
reference. | | java.lang.String | VARCHAR | Oracle | Oracle treats an empty string equals null. To workaround, JPOX replaces the empty string with the character \u0001. | | java.lang.String | UNIQUEIDENTIFIER | MSSQL | |
|