Home » Eclipse Projects » EclipseLink » ObjectArrayMapping and ClassDescriptor(Problems with ObjectArrayMapping setup.)
ObjectArrayMapping and ClassDescriptor [message #662729] |
Thu, 31 March 2011 12:49  |
Eclipse User |
|
|
|
I try to create ObjectArrayMapping using DescriptorCustomizer:
public class MyDescriptorCustomizer implements DescriptorCustomizer {
public void customize(ClassDescriptor descriptor) throws Exception {
// Set class descriptor to an aggregate collection.
descriptor.descriptorIsAggregateCollection();
// Delete old mapping (default) for my attribute:
descriptor.removeMappingForAttributeName("attributeName");
// Create new ObjectArrayMapping:
ObjectArrayMapping arrayMapping = new ObjectArrayMapping(); // Set up properties.
arrayMapping.setReferenceClass(MyClass.class);
arrayMapping.setAttributeName("attributeName");
arrayMapping.setFieldName("fieldName");
arrayMapping.setStructureName("structureName");
// Add mapping to descriptor.
descriptor.addMapping(arrayMapping);
}
}
Problem is the following: ObjectArrayMapping requires Class Descriptor to be an AggregateCollection, that's why I set this property for my descriptor.
But after it all other mappings (for other fields) which were of DirectToFieldMapping or AggregateObjectMapping types are lost, cause they require normal descriptor.
The exception which is thrown by Eclipse is following:
Caused by: Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [SELECT p FROM Wsensorstate p, Tkunde r WHERE r.kundeid = :kundeid AND p.id.providerid = r.providerid AND p.id.kundeid = :kundeid AND p.id.endgeraetid = :endgeraetid], line 1, column 72: unknown state or association field [id] of class [com.companyname.res.pull.api.entities.Wsensorstate]
Do you have any ideas how to avoid this problem? Or just an advice how to organize ObjectArrayMapping correctly?
Any help will be appreciated.
If you need Entity code or smth else, I can added. Thanks.
|
|
| |
Re: ObjectArrayMapping and ClassDescriptor [message #664162 is a reply to message #662938] |
Thu, 07 April 2011 12:59   |
Eclipse User |
|
|
|
Chris, thank you for your reply.
Probably I'm an idiot but I can't get it working. Let me describe you all the things done and probably you will show me any problem points.
I have entity:
@Entity
public class Wsensorstate implements Serializable {
[.........]
// Here is the problem column:
private List<CAlarmMess> alarme;
[.........]
}
I also have CAlarmMess class which is actually just a POJO:
public class CAlarmMess implements Serializable {
[.........]
private BigDecimal ereignisTypId;
private BigDecimal ereignisKlasseId;
private Date alarmZeit;
private String paramWert1;
private String paramWert2;
private String paramWert3;
[.........]
}
All the fields of this CAlarmMess class have corresponding fields in Oracle custom type.
I also have session customizer:
public class RPASessionCustomizer implements SessionCustomizer {
public void customize(Session session) throws Exception {
Server server = (Server) session;
ObjectRelationalDataTypeDescriptor objectRelationalDataTypeDescriptor = new ObjectRelationalDataTypeDescriptor();
objectRelationalDataTypeDescriptor.setJavaClass(CAlarmMess.class);
objectRelationalDataTypeDescriptor.setTableName("WSENSORSTATE");
objectRelationalDataTypeDescriptor.descriptorIsAggregate();
objectRelationalDataTypeDescriptor.setStructureName("CAlarmMess");
objectRelationalDataTypeDescriptor.addFieldOrdering("EreignisTypId");
objectRelationalDataTypeDescriptor.addFieldOrdering("EreignisKlasseId");
objectRelationalDataTypeDescriptor.addFieldOrdering("AlarmZeit");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert1");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert2");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert3");
objectRelationalDataTypeDescriptor.addDirectMapping("ereignisTypId", "getEreignisTypId", "setEreignisTypId", "EreignisTypId");
objectRelationalDataTypeDescriptor.addDirectMapping("ereignisKlasseId", "getEreignisKlasseId", "setEreignisKlasseId", "EreignisKlasseId");
objectRelationalDataTypeDescriptor.addDirectMapping("alarmZeit", "getAlarmZeit", "setAlarmZeit", "AlarmZeit");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert1", "getParamWert1", "setParamWert1", "ParamWert1");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert2", "getParamWert2", "setParamWert2", "ParamWert2");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert3", "getParamWert3", "setParamWert3", "ParamWert3");
server.addDescriptor(objectRelationalDataTypeDescriptor);
// Creates class descriptor for object-array mapping setup.
ClassDescriptor classDescriptor = new ClassDescriptor();
classDescriptor.setJavaClass(CAlarmMess.class);
classDescriptor.setTableName("WSENSORSTATE");
classDescriptor.descriptorIsAggregateCollection();
ObjectArrayMapping objectArrayMapping = new ObjectArrayMapping();
objectArrayMapping.setReferenceClass(Wsensorstate.class);
objectArrayMapping.setAttributeName("alarme");
objectArrayMapping.setFieldName("ALARME");
objectArrayMapping.setStructureName("CAlarmMessList");
classDescriptor.addMapping(objectArrayMapping);
server.addDescriptor(classDescriptor);
}
}
This session customizer is loaded on initialization, but it gives no result. The error message is the following:
Caused by: Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [[Ljava.lang.Object;@16f019f], of class [class [Ljava.lang.Object;], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[alarme-->WSENSORSTATE.ALARME]] with descriptor [RelationalDescriptor(com.tsystems.res.pull.api.entities.Wsensorstate --> [DatabaseTable(WSENSORSTATE)])], could not be converted to [class [B].
So Eclipselink can see only direct-to-field mapping with relational descriptor, so the conversion can't be done.
I can remind you the DB structure.
Problem column from table SQL script:
"ALARME" "ITMSYS"."CALARMMESSLIST"
Here is CAlarmMessList type:
create or replace TYPE CAlarmMessList AS VARRAY(15) OF CAlarmMess;
And CAlarmMess type:
create or replace TYPE CAlarmMess AS OBJECT (
EreignisTypId NUMBER(9),
EreignisKlasseId NUMBER(9),
AlarmZeit DATE,
ParamWert1 VARCHAR2(65 CHAR),
ParamWert2 VARCHAR2(65 CHAR),
ParamWert3 VARCHAR2(65 CHAR),
CONSTRUCTOR FUNCTION CAlarmMess RETURN SELF AS RESULT,
CONSTRUCTOR FUNCTION CAlarmMess(iEreignisTypId IN NUMBER, iEreignisKlasseId IN NUMBER, iAlarmZeit IN DATE) RETURN SELF AS RESULT,
CONSTRUCTOR FUNCTION CAlarmMess(iEreignisTypId IN NUMBER, iEreignisKlasseId IN NUMBER, iAlarmZeit IN DATE, iParamWert1IN VARCHAR2) RETURN SELF AS RESULT,
CONSTRUCTOR FUNCTION CAlarmMess(iEreignisTypId IN NUMBER, iEreignisKlasseId IN NUMBER, iAlarmZeit IN DATE, iParamWert1 IN VARCHAR2, iParamWert2 IN VARCHAR2) RETURN SELF AS RESULT
);
Do you see any problems here? What should I change?
I will greatly appreciate any help and further advices.
[Updated on: Thu, 07 April 2011 13:00] by Moderator
|
|
| | | |
Re: ObjectArrayMapping and ClassDescriptor [message #665359 is a reply to message #664657] |
Thu, 14 April 2011 08:40   |
Eclipse User |
|
|
|
Thanks for your reply, James.
Currently i have customizer and get error as described in my message on April, 7th.
If I change customizer in the way you suggested:
public class RPASessionCustomizer implements SessionCustomizer {
public void customize(Session session) throws Exception {
Server server = (Server) session;
ObjectRelationalDataTypeDescriptor objectRelationalDataTypeDescriptor = new ObjectRelationalDataTypeDescriptor();
objectRelationalDataTypeDescriptor.setJavaClass(CAlarmMess.class);
objectRelationalDataTypeDescriptor.setTableName("WSENSORSTATE");
objectRelationalDataTypeDescriptor.descriptorIsAggregate();
objectRelationalDataTypeDescriptor.setStructureName("CAlarmMess");
objectRelationalDataTypeDescriptor.addFieldOrdering("EreignisTypId");
objectRelationalDataTypeDescriptor.addFieldOrdering("EreignisKlasseId");
objectRelationalDataTypeDescriptor.addFieldOrdering("AlarmZeit");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert1");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert2");
objectRelationalDataTypeDescriptor.addFieldOrdering("ParamWert3");
objectRelationalDataTypeDescriptor.addDirectMapping("ereignisTypId", "getEreignisTypId", "setEreignisTypId", "EreignisTypId");
objectRelationalDataTypeDescriptor.addDirectMapping("ereignisKlasseId", "getEreignisKlasseId", "setEreignisKlasseId", "EreignisKlasseId");
objectRelationalDataTypeDescriptor.addDirectMapping("alarmZeit", "getAlarmZeit", "setAlarmZeit", "AlarmZeit");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert1", "getParamWert1", "setParamWert1", "ParamWert1");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert2", "getParamWert2", "setParamWert2", "ParamWert2");
objectRelationalDataTypeDescriptor.addDirectMapping("paramWert3", "getParamWert3", "setParamWert3", "ParamWert3");
server.addDescriptor(objectRelationalDataTypeDescriptor);
ClassDescriptor classDescriptor = session.getDescriptor(Wsensorstate.class);
classDescriptor.removeMappingForAttributeName("alarme");
ObjectArrayMapping objectArrayMapping = new ObjectArrayMapping();
objectArrayMapping.setReferenceClass(CAlarmMess.class);
objectArrayMapping.setAttributeName("alarme");
objectArrayMapping.setFieldName("ALARME");
objectArrayMapping.setStructureName("CAlarmMessList");
classDescriptor.addMapping(objectArrayMapping);
}
}
It gives me following error:
Exception [EclipseLink-197] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The mapping [alarme] is not the appropriate type for this descriptor
Mapping: org.eclipse.persistence.mappings.structures.ObjectArrayMapping[alarme]
Descriptor: RelationalDescriptor(com.companyname.api.entities.Wsensorstate --> [DatabaseTable(WSENSORSTATE)])
So the descriptor is relational descriptor, but I try to add aggregate mapping.
Any ideas?
|
|
|
Re: ObjectArrayMapping and ClassDescriptor [message #665417 is a reply to message #665359] |
Thu, 14 April 2011 10:59  |
Eclipse User |
|
|
|
You need to make the descriptor for Wsensorstate a ObjectRelationalDataTypeDescriptor as well.
You should be able to create a new one, define its primary key, table and mappings and register it with the session to override the JPA generated one. You could probably copy these over from the existing descriptor.
|
|
|
Goto Forum:
Current Time: Tue Jul 22 18:35:28 EDT 2025
Powered by FUDForum. Page generated in 0.03781 seconds
|