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,
 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