Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Virtual entities and XMLMetadataSource

Tom, thanks for all your help. Can you expand on what you mean by create a static entity with a one-to-one with the dynamic entity? How would that work?
 
Hi Harpreet,
Currently Dynamic entities are implemented using weaving and the weaving support will not take into account a parent class other than DynamicEntityImpl. As a result, I'm afraid you won't be able to create a dynamic entity that is a subclass of an existing entity. Please feel free to add an enhancement request.
Perhaps you can, instead create a static entity that has a One-to-One with the dynamic entity and hide relationship in your getters and setters.

-Tom


On Mon, Nov 12, 2012 at 12:00 PM, Harpreet Singh <hsingh9@xxxxxxxxx> wrote:
Hi Tom, 
  I'm looking for both. In my project I have a entity called Project, which is extensible and uses VirtualAccessMethods. Using this and XMLMetaDataSource I allow my user to add new attributes to the project entity. Now I want to go further and allow the user to create a SubProject entity for example. This new dynamic entity created by the user would extend entities that I ship, e.g. Project. I thought I could use DynamicEntities to achieve this. However, it seems Project would have to extend DynamicEntityImpl and implement the fetchPropertiesManager method, which I'm not sure how to do. Is this the only way to do this in eclipselink?

Hi Harpreet,
   Are you looking for a dynamic entity, or just an extensible entity?
   DynamicEntities must extend DynamicEntityImpl.  Any entity can be extensible.
  See:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensibility
-Tom


On Thu, Nov 8, 2012 at 2:38 PM, Harpreet Singh <hsingh9@xxxxxxxxx> wrote:
Tom,
 I get a little further with the latest 2.4.2 milestone. Now I get the error below. I guess this means that my user definable dynamic entity cannot extend something I ship in the product. Is there any other way to achieve this inheritance? I want the dynamic entity to extend the entity I ship with the product, which is not a dynamic entity.

Caused by: java.lang.IllegalArgumentException: DynamicClassLoader: com.foo.Project not compatible with parent class org.eclipse.persistence.internal.dynamic.DynamicEntityImpl
at org.eclipse.persistence.dynamic.DynamicClassLoader.checkAssignable(DynamicClassLoader.java:174)
at org.eclipse.persistence.dynamic.DynamicClassLoader.createDynamicClass(DynamicClassLoader.java:167)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClass(MetadataProject.java:844)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClass(MetadataProject.java:838)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClass(MetadataProject.java:838)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClasses(MetadataProject.java:865)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.createDynamicClasses(MetadataProcessor.java:153)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:469)
... 60 more


On Tue, Nov 6, 2012 at 5:30 PM, Harpreet Singh <hsingh9@xxxxxxxxx> wrote:
In my project I need to be able to create a dynamic entity which extends a regular entity. The dynamic/virtual entity definition is loaded at startup from a configuration database (not using eclipselink). For this I've created a XMLMetadataSource which provides eclipselink with the dynamic entity definition, however startup fails b/c eclipselink is using the real classloader instead of the dynamic classloader. I'm using EclipseLink 2.4.0.

Code from Metadatasource:

EntityAccessor accessor = new EntityAccessor();
    accessor.setName("SubProject");
    //dynamic entity
    accessor.setClassName("com.foo.SubProject");
    //regular entity, see com/foo/Project.java
    accessor.setParentClassName("com.foo.Project");
    accessor.setAccess("VIRTUAL");
    accessor.setDiscriminatorValue("SP");

    List<SecondaryTableMetadata> secondaryTables = new ArrayList<SecondaryTableMetadata>();
    SecondaryTableMetadata table = new SecondaryTableMetadata();
    table.setName("pln_sub_project");
    secondaryTables.add(table);
    accessor.setSecondaryTables(secondaryTables);

    //based on Metadatasource example
    addExtension(accessor, new Extension("com.foo.SubProject", "java.lang.String", "foo"));
    mappings.getEntities().add(accessor);

The problem seems to be here in EntityManagerSetupImpl#deploy(Classloader, Map)

processor.setClassLoader(realClassLoader);
processor.createDynamicClasses();

The processor ends up using the realClassLoader instead of the dynamic class loader supplied in PersistenceUnit properties resulting in the following error:

Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [p] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-7328] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.ValidationException
Exception Description: When using VIRTUAL access a DynamicClassLoader must be provided when creating the entity manager factory using the eclipselink property [eclipselink.classloader]. That is, createEntityManagerFactory(String persistenceUnitName, Map properties) and add a new DynamicClassLoader() to the Map properties.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:229)
... 62 more
Caused by: Exception [EclipseLink-7328] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.ValidationException
Exception Description: When using VIRTUAL access a DynamicClassLoader must be provided when creating the entity manager factory using the eclipselink property [eclipselink.classloader]. That is, createEntityManagerFactory(String persistenceUnitName, Map properties) and add a new DynamicClassLoader() to the Map properties.
at org.eclipse.persistence.exceptions.ValidationException.invalidClassLoaderForDynamicPersistence(ValidationException.java:1070)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClasses(MetadataProject.java:861)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.createDynamicClasses(MetadataProcessor.java:153)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:463)
... 60 more
[EL Severe]: ejb: 2012-11-06 17:17:42.19--ServerSession(29272897)--Thread(Thread[http-bio-8080-exec-3,5,main])--Local Exception Stack: 
Exception [EclipseLink-7328] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.ValidationException
Exception Description: When using VIRTUAL access a DynamicClassLoader must be provided when creating the entity manager factory using the eclipselink property [eclipselink.classloader]. That is, createEntityManagerFactory(String persistenceUnitName, Map properties) and add a new DynamicClassLoader() to the Map properties.
at org.eclipse.persistence.exceptions.ValidationException.invalidClassLoaderForDynamicPersistence(ValidationException.java:1070)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.createDynamicClasses(MetadataProject.java:861)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.createDynamicClasses(MetadataProcessor.java:153)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:463)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:186)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getMetamodel(EntityManagerFactoryDelegate.java:602)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:516)




Back to the top