[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| 
Re: [eclipselink-users] Setting Foreign Reference Mappings to	Read-Only
 | 
  
  
    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
       
     
  
 | 
import org.eclipse.persistence.dynamic.DynamicClassLoader;
import org.eclipse.persistence.dynamic.DynamicHelper;
import org.eclipse.persistence.dynamic.DynamicTypeBuilder;
import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl;
import org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder;
import org.eclipse.persistence.sessions.DatabaseLogin;
import org.eclipse.persistence.sessions.DatabaseSession;
public class MultipleWritableMappingsTest
{
    public static void main(String[] args)
    {
        DatabaseLogin login = new DatabaseLogin();
        login.setUserName("******");
        login.setPassword("******");
        login.setDriverURLHeader("jdbc:oracle:thin:@");
        login.setDriverClassName("oracle.jdbc.OracleDriver");
        login.setDatabaseURL("****************************");
        DatabaseSession session = new DatabaseSessionImpl(login);
        session.login();
        DynamicHelper helper = new DynamicHelper(session);
        DynamicClassLoader dcl = helper.getDynamicClassLoader();
        Class<?> t1Type = dcl.createDynamicClass("jpatest.t1");
        DynamicTypeBuilder t1Builder = new JPADynamicTypeBuilder(t1Type, null, "t1");
        t1Builder.setPrimaryKeyFields("a1", "b1");
        t1Builder.addDirectMapping("a1", String.class, "a1");
        t1Builder.addDirectMapping("b1", String.class, "b1");
        t1Builder.addDirectMapping("c1", String.class, "c1");
        t1Builder.addDirectMapping("d1", String.class, "d1");
        t1Builder.addDirectMapping("e1", String.class, "e1");
        Class<?> t2Type = dcl.createDynamicClass("jpatest.t2");
        DynamicTypeBuilder t2Builder = new JPADynamicTypeBuilder(t2Type, null, "t2");
        t2Builder.setPrimaryKeyFields("a2", "b2");
        t2Builder.addDirectMapping("a2", String.class, "a2");
        t2Builder.addDirectMapping("b2", String.class, "b2");
        t2Builder.addDirectMapping("c2", String.class, "c2");
        t2Builder.addDirectMapping("d2", String.class, "d2");
        t2Builder.addDirectMapping("e2", String.class, "e2");
        Class<?> t6Type = dcl.createDynamicClass("jpatest.t6");
        DynamicTypeBuilder t6Builder = new JPADynamicTypeBuilder(t6Type, null, "t6");
        t6Builder.setPrimaryKeyFields("a6");
//        t6Builder.addDirectMapping("a6", String.class, "a6");
        t6Builder.addDirectMapping("b6", String.class, "b6");
        t6Builder.addDirectMapping("c6", String.class, "c6");
        t6Builder.addDirectMapping("d6", String.class, "d6");
        t6Builder.addDirectMapping("e6", String.class, "e6");
        t6Builder.addOneToManyMapping("t1.t6", t1Builder.getType(), "b1");
        t1Builder.addOneToOneMapping("t1.t6", t6Builder.getType(), "b1").setIsReadOnly(true);
        
        helper.addTypes(false, false, t1Builder.getType(), t2Builder.getType(), t6Builder.getType());
    }