Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Custom MetadataSource and Dynamic Weaving
Custom MetadataSource and Dynamic Weaving [message #788282] Wed, 01 February 2012 10:47 Go to next message
Mike Gorman is currently offline Mike Gorman
Messages: 6
Registered: February 2012
Junior Member
I need to specify all mapping information dynamically, at runtime. I was pleased to see support added for this in EclipseLink 2.3.0:

wiki.eclipse.org/EclipseLink/Examples/JPA/MetadataSource

However, I also need weaving to take place dynamically, so I have specified -javaagent:eclipselink.jar as a JVM argument.

What I find is this: If my eclipselink-orm.xml is returned dynamically via a custom MetadataSource implementation, no weaving takes place. I get a message like this, instead:

Quote:
> Reverting the lazy setting on the OneToOne or ManyToOne attribute (createdBy) for the entity class (class com.rivermine.or.jpa.eclipselink.UserGroup) since weaving was not enabled or did not occur.


Yet if I take the exact same XML produced by my custom MetadataSource, and paste it into a real eclipselink-orm.xml file within META-INF, then the weaving does take place.

I can provide a complete test harness to demonstrate but thought I would just ask, first. Can anyone confirm or deny whether dynamic weaving is compatible with custom MetadataSources or what it is I need to do to get dynamic weaving enabled when using a custom MetadataSource? Thanks in advance.
Re: Custom MetadataSource and Dynamic Weaving [message #788470 is a reply to message #788282] Wed, 01 February 2012 16:26 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1016
Registered: July 2009
Senior Member
As per http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving
Dynamic weaving is performed at runtime, when Entities are loaded. Once they are loaded it is too late for them to be woven again, and so this cannot work the way you are intending it to with a MetadataSource repository.

Best Regards,
Chris
Re: Custom MetadataSource and Dynamic Weaving [message #788494 is a reply to message #788470] Wed, 01 February 2012 16:59 Go to previous messageGo to next message
Mike Gorman is currently offline Mike Gorman
Messages: 6
Registered: February 2012
Junior Member
I appreciate and understand that. Once the class is loaded, whatever weaving we need to do needs to get done then. But my CustomMetadataSource is the only thing in the system that should be telling the weaver (javaagent) what to weave. Thus, no attempt to load the class should be made until after the CustomMetadataSource returns the entity mappings.

So what I find is that if the mappings are described in a physical eclipselink-orm.xml file in my classpath, entities get weaved. If, instead, I generate the exact same mappings via the CustomMetadataSource (which extends XMLMetadataSource), entities do not get weaved.

For your reference, stand-alone test class:

Map<String, String> props = createJDBCProps();
props.put("eclipselink.metadata-source", CustomMetadataSource.class.getName());
EntityManagerFactory factory = Persistence.createEntityManagerFactory("default", props);
testWeaving(factory);


Source to my CustomMetadataSource is attached. (I referred to it as CustomMetadataSource above for discussion purposes but the class is actually named EclipseLinkMetadataSource so just ignore the discrepancy.)

[Updated on: Wed, 01 February 2012 17:00]

Report message to a moderator

Re: Custom MetadataSource and Dynamic Weaving [message #788496 is a reply to message #788470] Wed, 01 February 2012 16:59 Go to previous messageGo to next message
Mike Gorman is currently offline Mike Gorman
Messages: 6
Registered: February 2012
Junior Member
I appreciate and understand that. Once the class is loaded, whatever weaving we need to do needs to get done then. But my CustomMetadataSource is the only thing in the system that should be telling the weaver (javaagent) what to weave. Thus, no attempt to load the class should be made until after the CustomMetadataSource returns the entity mappings.

So what I find is that if the mappings are described in a physical eclipselink-orm.xml file in my classpath, entities get weaved. If, instead, I generate the exact same mappings via the CustomMetadataSource (which extends XMLMetadataSource), entities do not get weaved.

[Updated on: Thu, 02 February 2012 08:12]

Report message to a moderator

Re: Custom MetadataSource and Dynamic Weaving [message #788983 is a reply to message #788496] Thu, 02 February 2012 08:14 Go to previous message
Mike Gorman is currently offline Mike Gorman
Messages: 6
Registered: February 2012
Junior Member
Just wanted to provide an update. The problem had to do with the way I was dynamically generating my eclipselink-orm.xml. The class that was generating it was concatenating the full class name of the persistent entities into the XML by referencing them like User.class.getName(). Well this forces the system ClassLoader to load in the class before the weaver gets a chance to do its thing. Changed that to just a pure String and everything works now.
Re: Custom MetadataSource and Dynamic Weaving [message #788985 is a reply to message #788496] Thu, 02 February 2012 08:14 Go to previous message
Mike Gorman is currently offline Mike Gorman
Messages: 6
Registered: February 2012
Junior Member
Just wanted to provide an update. The problem had to do with the way I was dynamically generating my eclipselink-orm.xml. The class that was generating it was concatenating the full class name of the persistent entities into the XML by referencing them like User.class.getName(). Well this forces the system ClassLoader to load in the class before the weaver gets a chance to do its thing. Changed that to just a pure String and everything works now.
Previous Topic:JPA Partitioning and Spring
Next Topic:getAcessor() method undefined for UnitOfWork.
Goto Forum:
  


Current Time: Thu Jul 24 21:54:43 EDT 2014

Powered by FUDForum. Page generated in 0.02247 seconds