Hi Heather, OpenJPA supports persisting primitive arrays, but IIRC, you must either:
a) Annotate your primitive array with @Lob. The array will get stored as a serialized bytes in the database (and deserialized when retrieved). ex: @Lob double[] mDoubleArray; b) Use the OpenJPA @org.apache.openjpa.persistence.PersistentCollection annotation. This will result in the primitive array being stored in a separate table in the database. JPA 2.0 has an equivalent annotation @ElementCollection, so switching from an OpenJPA specific annotation to standard JPA annotation will be straight forward when moving from OpenJPA 1.2 to OpenJPA 2.0 if/when you choose to do so. Arguably, this is a cleaner approach since it uses typed columns in the database vs. serialized bytes. However, using lobs may prove to perform better. If you want the array to retain to proper order use the @OrderColumn annotation as well. ex: @PersistentCollection @OrderColumn double[] myDoubleArray; It appears that OpenJPA treats an array of primitive wrappers (Double[]) as if it were tagged as a Lob. Perhaps we should be doing the same with arrays of primitives? hth, -Jeremy On Fri, Apr 10, 2009 at 3:45 PM, Heather Sterling <[email protected]> wrote: > > > I am trying to understand whether OpenJPA supports primitive arrays or not. > I am able to persist arrays just fine if they are primitive wrapper classes > ( e.g. Double[]). However, I get the following exception for primitive > arrays (e.g. double[]): > > <openjpa-1.2.0-r422266:683325 fatal user error> > org.apache.openjpa.util.MetaDataException: The type of field > > "com.ibm.sysmgmt.resource.caching.jpa.test.entities.PropertyTestElement.mDoubleArray" > isn't supported by declared persistence strategy "Basic". Please choose a > different strategy. > at > > org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parseBasic > ( > AnnotationPersistenceMetaDataParser.java:1264) > > The OpenJPA manual claims the following:: > > OpenJPA also supports arrays, java.lang.Number, java.util.Locale, all JDK > 1.2 Set, List, and Map > types, and many other mutable and immutable field types. OpenJPA also > allows you to plug in support for custom types. > > 1) Are primitive arrays supported? If so, what strategy should be used > besides Basic? > 2) Should I use the wrapper classes when persisting arrays? > > Thanks > > Heather Sterling > Systems Management Development > Phone: 919-254-7163 T/L: 444-7163 > Cell: 919-423-3143 > Email: [email protected]
