[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: AW: [eclipselink-users] Beginner question concerning Collectionsand Maps in JPA
|
Hi Daniel,
At the moment, our @BasicMap and @BasicCollection support will not cover
LOBs. There are a few things you can try:
1. It may be possible to do this with a converter. The idea is that you would
write a converter class that would do the conversion for you. That class would
implement a couple of methods that convert the value when going back and forth
from the database. Here is some initial documentation about Converters:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_the_.40Converter_Annotation
2. There is a chance that setting the SQL type on the underlying mapping will
help. To do this, you will have to use a descriptor customizer. In that
descriptor customizer, you would get the appropriate mapping and call
setSQLType(java.sql.Types.BLOB). I have not actually tried this, but there is a
chance it could work. Here is the documentation about customizers:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Customization_and_Optimization
3. If all else fails, you could wrap your BLOB in an Entity, map it directly on
that class with the annotations you mention below. You could then write some
methods on the owning class that hid the fact that the entity exists at all.
-Tom
Daniel.Stucky@xxxxxxxxxxx wrote:
Hi Tom,
thanks for your answer. With the extensions I was easily able to annotate List<String> and Map<String, String>.
Is it also possible to use Map<String, byte[]> ?
I tried it out and got an Internal Exception: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
I know from the documentation that it's possible to use byte[] as fields, like
@Lob
@Basic(fetch=LAZY)
@Column(name="EMP_PIC", columnDefinition="BLOB NOT NULL")
protected byte[] pic;
I also tried to somehow combine the annotations for the byte[] with the @BasicMap extension, but without any success so far.
Bye,
Daniel
-----Ursprüngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-
bounces@xxxxxxxxxxx] Im Auftrag von Tom Ware
Gesendet: Donnerstag, 22. Januar 2009 15:03
An: EclipseLink User Discussions
Betreff: Re: [eclipselink-users] Beginner question concerning
Collectionsand 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
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users