Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Beginner question concerning Collections and Maps in JPA

Hi Daniel,

The problem you are seeing is because Lists and Maps of primitives are covered by an EclipseLink extension to JPA rather than the specification itself. Take a look at the following documentation for information on how to use those extensions:

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_the_.40BasicCollection_Annotation
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_the_.40BasicMap_Annotation

If you are concerned about using JPA in a portable manner, it is my understanding that the upcoming JPA 2.0 specification will cover those scenarios. EclipseLink is the reference implementation for that specification and will ship an implementation with the specification.

-Tom

Daniel.Stucky@xxxxxxxxxxx wrote:
Hi all,

I'm from the SMILA project and new to eclipseLink. Some of the 3rd party
components we use in SMILA already make use of eclipseLink, so we are
thinking about using eclipseLink (JPA) for persisting our own data as
well.

Our datamodel, being recursive, is a bit complex. Here is an overview of
the classes containing only the member variables that need to be
persisted.
public class RecordImpl implements Record, Serializable {
  private IdImpl _id;
  private MObject _metadata = new MObjectImpl();
  private final Map<String, byte[]> _attachments = new
LinkedHashMap<String, byte[]>();
  ...
}


public class IdImpl implements Id {
  private String _source;
  private Key _key;
  private List<KeyImpl> _elementKeys;
  private List<String> _fragmentNames;
  ...
}


public class KeyImpl implements Key {
  private String _simpleKey;
  private String _simpleKeyName;
  private Map<String, String> _compositeKey;
  ...
}


public class MObjectImpl extends AttributeValueImpl implements MObject {
  private final Map<String, AttributeImpl> _attributes = new
LinkedHashMap<String, AttributeImpl>();
  ...
}


public class AttributeImpl extends AnnotatableImpl implements Attribute
{
 private String _name;
  private List<LiteralImpl> _literalValues;
  private List<MObjectImpl> _metadataObjects;
  ...
}


public abstract class AttributeValueImpl extends AnnotatableImpl
implements AttributeValue {
  private String _semanticType;
  ...
}


public abstract class AnnotatableImpl implements Annotatable,
Serializable {
  private MultiValueMap _annotationMap;
  ...
}


public class LiteralImpl extends AttributeValueImpl implements Literal {
  private Object _value;
  private DataType _dataType;
  ...
}


To get started I annotated all members with @Transient and tried to
replace every one step by step with "correct annotations".
Currently I'm running into problems finding the right annotations for
the Collections and Maps. I read a lot about it in your documentation
(thumbs up, it's really extensive) but I'm not able to understand the
meaning of the annotations and so can't find answers to my problems.

E.g.
- for Map<String, String> the follwoing error message occurs:
Exception Description: [class
org.eclipse.smila.datamodel.id.impl.KeyImpl] uses a non-entity [class
java.lang.String] as target entity in the relationship attribute
[private java.util.Map
org.eclipse.smila.datamodel.id.impl.KeyImpl._compositeKey].
- for List<String> _fragmentNames the follwoing error message occurs:
Exception Description: [class
org.eclipse.smila.datamodel.id.impl.IdImpl] uses a non-entity [class
java.lang.String] as target entity in the relationship attribute
[private org.eclipse.smila.datamodel.id.impl.IdImpl._fragmentNames].



It would be great if I could get some feedback about
- if it's generally possible to persist our datamodel with eclipseLink
JPA or if there are java constructs that are simply not supported by
JPA/eclipseLink
- how to annotate collections and maps
- how to use non entity classes in collections/maps

Thanks a lot !

Bye,
Daniel
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top