Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Setting Foreign Reference Mappings to Read-Only

You can set either the direct or one-to-one to read-only.  This should not
have a big impact, the target object should still be persisted.  The foreign
key will be written by the direct, so ensure that this is set before
persisting the object.

You should also be able to remove the direct, and just have the one-to-one,
which is normally the best way to go.


Rohit Banga-2 wrote:
> 
> Hi Chris
> <br>
> <br>
> 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'.
> 
> <br>
> 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.
> 
> <br>
> 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?<br>
>     <br>
> 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?<br>
> 
> <br>
> Thanks
> <br>
> Rohit
> 
> 
> <br>----- Original Message -----<br>From:
> christopher.delahunt@xxxxxxxxxx<br>To: rohit.banga@xxxxxxxxxx,
> eclipselink-users@xxxxxxxxxxx<br>Sent: Monday, April 18, 2011 9:46:18 PM
> GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi<br>Subject: Re:
> [eclipselink-users] Setting Foreign Reference Mappings to
> Read-Only<br><br><head>
>   
>   <title></title>
> <link rel="stylesheet" href="/zimbra/css/msgview.css?v=1.0"></head>
> <body style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
> margin-left: 0px; " class="MsgBody MsgBody-html"><div>
> Hello Rohit,<br>
> <br>
> 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:<br>
> t6Builder.setPrimaryKeyFields("a6");<br>
> //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> t6Builder.addDirectMapping("a6", String.class, "a6");<br>
> <br>
> The error is occuring because when you comment the a6 mapping out, the
> field no longer has a way to be set.&nbsp; 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?<br>
> <br>
> Best Regards,<br>
> Chris<br>
> <br>
> On 18/04/2011 10:59 AM, Rohit Banga wrote:
> <blockquote cite="mid:4DAC51E7.6050503@xxxxxxxxxx">
>   
> Hi<br>
>   <br>
> I have attached a sample program showing three tables - T1, T2, T6.<br>
>   <br>
> Ti has columns ai,bi, ... ei. i=1,2,6.<br>
>   <br>
> T1 has primary key a1,b1.<br>
> T2 has primary key a2,b2.<br>
> T6 has primary key a6,b6.<br>
>   <br>
> The attached program throws the following exception. Can this be fixed
> somehow?<br>
>   <big><tt><br>
> Exception [EclipseLink-46] (Eclipse Persistence Services -
> 2.2.0.v20110107-r8783):
> org.eclipse.persistence.exceptions.DescriptorException<br>
> Exception Description: There should be one non-read-only mapping
> defined for the primary key field [t6.a6].<br>
> Descriptor: RelationalDescriptor(jpatest.t6 --&gt;
> [DatabaseTable(t6)])<br>
>   <br>
> Runtime Exceptions: <br>
> ---------------------------------------------------------<br>
>   <br>
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0<br>
>   <br>
> &nbsp;&nbsp;&nbsp; at
> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:547)<br>
> &nbsp;&nbsp;&nbsp; at
> org.eclipse.persistence.sessions.Project.addDescriptors(Project.java:295)<br>
> &nbsp;&nbsp;&nbsp; at
> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.addDescriptors(DatabaseSessionImpl.java:226)<br>
> &nbsp;&nbsp;&nbsp; at
> org.eclipse.persistence.dynamic.DynamicHelper.addTypes(DynamicHelper.java:222)<br>
>   </tt></big><br>
>   <br>
> Thanks in Advance!<br>
>   <br>
> On 4/18/2011 7:21 PM, Rohit Banga wrote:
>   <blockquote cite="mid:4DAC41F6.3090000@xxxxxxxxxx">
>     
> Hi All<br>
>     <br>
>     To avoid <tt>ECLIPSELINK-00046</tt>, <tt>ECLIPSELINK-00048</tt> (
> http://wiki.eclipse.org/EclipseLink_Exception_Error_Reference_%28ELUG%29
> http://wiki.eclipse.org/EclipseLink_Exception_Error_Reference_%28ELUG%29 )
> with Dynamic JPA, I am planning to use the following strategy.<br>
>     <br>
> 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.<br>
>     <br>
> Can someone please clarify the following:<br>
>     <br>
> 1. Is the above a reasonable and safe way to avoid the exceptions at
> runtime?<br>
>     <br>
> 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?<br>
>     <br>
>     <br>
>     <div class="moz-signature">-- <br>
> Thanks and Regards <br>
> Rohit Banga <br>
> Member Technical Staff <br>
> Oracle Server Technologies <br>
>     </div>
>     <pre><fieldset class="mimeAttachmentHeader"></fieldset>
> 
> </body>
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/Setting-Foreign-Reference-Mappings-to-Read-Only-tp31424061p31441588.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top