Hi Chris
Initially I had uncommented that line and did not set the read only property to true on the mapping. It through the same exceptions. Then I set the read only property to true on the mapping. The exception disappeared. The exception says that multiple writable mappings have been defined for the field 'b1' and 'a6'.
All primary key fields must have one non read-only mapping defined. It seems that the Foreign reference mapping suffices as a mapping for the field. So I thought that the Direct To Field Mapping will not be required for 'a6'. I tried commenting out the line expecting the foreign reference mapping to be an alternative but it is set to read-only as 'b1' has a direct to field mapping defined.
May be the program does not reflect my original question correctly.
Coming back to my original question:
1. Is setting the read-only property to true for all extraneous mappings a reasonable and safe way to avoid these exceptions at runtime?
2. What is the impact of having a foreign reference mapping as
read-only? Can I not persist changes to the target entity of the
mapping?
Thanks
Rohit
----- Original Message ----- From: christopher.delahunt@xxxxxxxxxx To: rohit.banga@xxxxxxxxxx, eclipselink-users@xxxxxxxxxxx Sent: Monday, April 18, 2011 9:46:18 PM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi Subject: Re: [eclipselink-users] Setting Foreign Reference Mappings to Read-Only
Hello Rohit,
Not sure what you are after exactly, as you say a6 and b6 are your pks
for T6, but in the file you sent, you show:
t6Builder.setPrimaryKeyFields("a6");
// t6Builder.addDirectMapping("a6", String.class, "a6");
The error is occuring because when you comment the a6 mapping out, the
field no longer has a way to be set. Is there a reason you are
commenting this line out, or why you don't have both a6 and b6 being
defined as primary key fields in the descriptor?
Best Regards,
Chris
On 18/04/2011 10:59 AM, Rohit Banga wrote:
Hi
I have attached a sample program showing three tables - T1, T2, T6.
Ti has columns ai,bi, ... ei. i=1,2,6.
T1 has primary key a1,b1.
T2 has primary key a2,b2.
T6 has primary key a6,b6.
The attached program throws the following exception. Can this be fixed
somehow?
Exception [EclipseLink-46] (Eclipse Persistence Services -
2.2.0.v20110107-r8783):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping
defined for the primary key field [t6.a6].
Descriptor: RelationalDescriptor(jpatest.t6 --> [DatabaseTable(t6)])
Runtime Exceptions:
---------------------------------------------------------
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:547)
at
org.eclipse.persistence.sessions.Project.addDescriptors(Project.java:295)
at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.addDescriptors(DatabaseSessionImpl.java:226)
at
org.eclipse.persistence.dynamic.DynamicHelper.addTypes(DynamicHelper.java:222)
Thanks in Advance!
On 4/18/2011 7:21 PM, Rohit Banga wrote:
Hi All
To avoid ECLIPSELINK-00046, ECLIPSELINK-00048 (http://wiki.eclipse.org/EclipseLink_Exception_Error_Reference_%28ELUG%29)
with Dynamic JPA, I am planning to use the following strategy.
If a DirectToFieldMapping is defined for a primary key field of a
DynamicType, then for any OneToOneMapping that uses this field set the
OneToOneMapping as read-only.
Can someone please clarify the following:
1. Is the above a reasonable and safe way to avoid the exceptions at
runtime?
2. What is the impact of having a foreign reference mapping as
read-only? Can I not persist changes to the target entity of the
mapping?
--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|