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 JPA specification define lists of types that are required to be supported by all implementations of those specifications. This support can be conveniently split into two parts
An object that can be referred to (object reference, providing a relation) and that has an "identity" is termed a First Class Object (FCO). DataNucleus supports the following Java types as FCO
An object that does not have an "identity" is termed a Second Class Object (SCO). This is something like a String or Date field in a class, or alternatively a Collection (that contains other objects). The table below shows the currently supported SCO java types in DataNucleus. The table shows
| Java Type | Extension? | EAGER? | Persistent? | Proxied? | PK? | Plugin |
|---|---|---|---|---|---|---|
| boolean | datanucleus-core | |||||
| byte | datanucleus-core | |||||
| char | datanucleus-core | |||||
| double | datanucleus-core | |||||
| float | datanucleus-core | |||||
| int | datanucleus-core | |||||
| long | datanucleus-core | |||||
| short | datanucleus-core | |||||
| boolean[] | ![]() |
datanucleus-core | ||||
| byte[] | datanucleus-core | |||||
| char[] | datanucleus-core | |||||
| double[] | ![]() |
datanucleus-core | ||||
| float[] | ![]() |
datanucleus-core | ||||
| int[] | ![]() |
datanucleus-core | ||||
| long[] | ![]() |
datanucleus-core | ||||
| short[] | ![]() |
datanucleus-core | ||||
| java.lang.Boolean | datanucleus-core | |||||
| java.lang.Byte | datanucleus-core | |||||
| java.lang.Character | datanucleus-core | |||||
| java.lang.Double | datanucleus-core | |||||
| java.lang.Float | datanucleus-core | |||||
| java.lang.Integer | datanucleus-core | |||||
| java.lang.Long | datanucleus-core | |||||
| java.lang.Short | datanucleus-core | |||||
| java.lang.Boolean[] | ![]() |
datanucleus-core | ||||
| java.lang.Byte[] | datanucleus-core | |||||
| java.lang.Character[] | datanucleus-core | |||||
| java.lang.Double[] | ![]() |
datanucleus-core | ||||
| java.lang.Float[] | ![]() |
datanucleus-core | ||||
| java.lang.Integer[] | ![]() |
datanucleus-core | ||||
| java.lang.Long[] | ![]() |
datanucleus-core | ||||
| java.lang.Short[] | ![]() |
datanucleus-core | ||||
| java.lang.Number [4] | ![]() |
datanucleus-core | ||||
| java.lang.Object | ![]() |
datanucleus-core | ||||
| java.lang.String | datanucleus-core | |||||
| java.lang.StringBuffer [3] | ![]() |
datanucleus-core | ||||
| java.lang.String[] | ![]() |
datanucleus-core | ||||
| java.lang.Class | ![]() |
datanucleus-core | ||||
| java.math.BigDecimal | datanucleus-core | |||||
| java.math.BigInteger | datanucleus-core | |||||
| java.math.BigDecimal[] | ![]() |
datanucleus-core | ||||
| java.math.BigInteger[] | ![]() |
datanucleus-core | ||||
| java.sql.Date | datanucleus-core | |||||
| java.sql.Time | datanucleus-core | |||||
| java.sql.Timestamp | datanucleus-core | |||||
| java.util.ArrayList | datanucleus-core | |||||
| java.util.BitSet | datanucleus-core | |||||
| java.util.Calendar | datanucleus-core | |||||
| java.util.Collection | datanucleus-core | |||||
| java.util.Currency | ![]() |
datanucleus-core | ||||
| java.util.Date | datanucleus-core | |||||
| java.util.Date[] | ![]() |
datanucleus-core | ||||
| java.util.GregorianCalendar [7] | datanucleus-core | |||||
| java.util.HashMap | datanucleus-core | |||||
| java.util.HashSet | datanucleus-core | |||||
| java.util.Hashtable | datanucleus-core | |||||
| java.util.LinkedHashMap [5] | datanucleus-core | |||||
| java.util.LinkedHashSet [6] | datanucleus-core | |||||
| java.util.LinkedList | datanucleus-core | |||||
| java.util.List | datanucleus-core | |||||
| java.util.Locale | ![]() |
datanucleus-core | ||||
| java.util.Locale[] | ![]() |
datanucleus-core | ||||
| java.util.Map | datanucleus-core | |||||
| java.util.Properties | ![]() |
datanucleus-core | ||||
| java.util.PriorityQueue | ![]() |
datanucleus-core | ||||
| java.util.Queue | ![]() |
datanucleus-core | ||||
| java.util.Set | datanucleus-core | |||||
| java.util.SortedMap [2] | ![]() |
datanucleus-core | ||||
| java.util.SortedSet [1] | ![]() |
datanucleus-core | ||||
| java.util.Stack | ![]() |
datanucleus-core | ||||
| java.util.TimeZone | datanucleus-core | |||||
| java.util.TreeMap [2] | datanucleus-core | |||||
| java.util.TreeSet [1] | datanucleus-core | |||||
| java.util.UUID | ![]() |
datanucleus-core | ||||
| java.util.Vector | datanucleus-core | |||||
| java.awt.Color | ![]() |
datanucleus-core | ||||
| java.awt.image.BufferedImage | ![]() |
datanucleus-core | ||||
| java.awt.Point | ![]() |
datanucleus-awtgeom | ||||
| java.awt.Rectangle | ![]() |
datanucleus-awtgeom | ||||
| java.net.URI | ![]() |
datanucleus-core | ||||
| java.net.URL | ![]() |
datanucleus-core | ||||
| java.io.Serializable | datanucleus-core | |||||
| persistable | datanucleus-core | |||||
| persistable[] | ![]() |
datanucleus-core | ||||
| java.lang.Enum | datanucleus-core | |||||
| java.lang.Enum[] | datanucleus-core | |||||
| javax.time.calendar.LocalDateTime | ![]() |
datanucleus-javaxtime | ||||
| javax.time.calendar.LocalTime | ![]() |
datanucleus-javaxtime | ||||
| javax.time.calendar.LocalDate | ![]() |
datanucleus-javaxtime | ||||
| org.joda.time.DateTime | ![]() |
datanucleus-jodatime | ||||
| org.joda.time.LocalTime | ![]() |
datanucleus-jodatime | ||||
| org.joda.time.LocalDate | ![]() |
datanucleus-jodatime | ||||
| org.joda.time.Duration | ![]() |
datanucleus-jodatime | ||||
| org.joda.time.Interval | ![]() |
datanucleus-jodatime | ||||
| org.joda.time.Period | ![]() |
datanucleus-jodatime | ||||
| com.google.common.collect.Multiset | ![]() |
datanucleus-googlecollections |
Note that support is available for persisting other types depending on the datastore to which you are persisting
If you have support for any additional types and would either like to contribute them, or have them listed here, let us know
You can add support for other basic Java types quite easily, particularly if you can store
it as a String or Long and then retrieve it back into its object form from that -
See the Java Types plugin-point
You can also define more specific support for it with RDBMS datastores -
See the RDBMS Java Types plugin-point
JPA2.1 is introducing an API for conversion of an attribute of an Entity to its datastore value. You can define a "converter" that will convert to the datastore value and back from it, implementing this interface.
public interface AttributeConverter<X,Y>
{
public Y convertToDatabaseColumn (X attributeObject);
public X convertToEntityAttribute (Y dbData);
}so if we have a simple converter to allow us to persist fields of type URL in a String form in the datastore, like this
public class URLStringConverter implements AttributeConverter<URL, String>
{
public URL convertToEntityAttribute(String str)
{
if (str == null)
{
return null;
}
URL url = null;
try
{
url = new java.net.URL(str.trim());
}
catch (MalformedURLException mue)
{
throw new IllegalStateException("Error converting the URL", mue);
}
return url;
}
public String convertToDatabaseColumn(URL url)
{
return url != null ? url.toString() : null;
}
}
and now in our Entity class we mark any URL field as being converted using this converter
@Entity
public class MyClass
{
@Id
long id;
@Basic
@Convert(converter=URLStringConverter.class)
URL url;
...
}You could try to persist Eclipse EMF models using the Texo project to generate POJOs