Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Dynamic JPA

I have a use case where the “types” in my application are created dynamically so the JPA entity’s Java .class is not present at startup.  To accommodate this functionality, my object model and DB schema store the data in a very abstract form.  My thought was to use EclipseLink’s Dynamic Persistence functionality to create dynamic entity types and then configure their mappings against DB Views which are also dynamically created rather than map directly to the underlying general tables.  The dynamic entity types and DB views would only be used to search the data (read only).  Persistence and update of the data would be done using a different set of JPA mappings.

 

The problem I encountered is that since my DB view does not have a primary key,! the primary key constraint being on the backing table, I get exception shown below.  If I attempt to leave off the primary key mapping I get a different exception.  Is what I am trying to do even possible?

 

Exception [EclipseLink-46] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException

Exception Description: There should be one non-read-only mapping defined for the primary key field [Component.UUID].

Descriptor: RelationalDescriptor(my.co.domain.Component --> [DatabaseTable(Component)])

 

 

        Class<?> dynamicClass = dcl.createDynamicClass(packagePrefix + "Component");

        JPADynamicTypeBuilder compType = new JPADynamicTypeBuilder(dynamicClass, null, dbViewName);

       

        viewType.setPrimaryKeyFields("UUID");

        viewType.addDirectMapping("name", String.class, "NAME");

        viewType.addDirectMapping("description", String.class, "DESC ");

 

!

 

Any suggestions you can provide on the approach or alternative approaches would be greatly appreciated. 

 

Thanks,

 

Dennis Fuglsang

 


Back to the top