Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Virtual entities and XMLMetadataSource
Virtual entities and XMLMetadataSource [message #974160] Tue, 06 November 2012 22:42
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 3
Registered: November 2010
Junior Member
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)
Previous Topic:Eclipselink and JPA
Next Topic:TopLink to EclipseLink migration
Goto Forum:
  


Current Time: Fri Apr 19 16:34:39 GMT 2024

Powered by FUDForum. Page generated in 0.01626 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top