Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Dynamic entities: adding properties after initialization
Dynamic entities: adding properties after initialization [message #890024] Wed, 20 June 2012 16:02 Go to next message
Thomas Gillet is currently offline Thomas GilletFriend
Messages: 14
Registered: May 2011
Junior Member
Hello everybody,

I'm starting to use the dynamic entities (package org.eclipse.persistence.dynamic), and I managed to create a new dynamic type and use it to persist some entities.

But it appeared to me that properties can only be added to this dynamic type before the call to jpaDynamicHelper.addTypes(...).
Adding a property afterwards doesn't throw any error, but then the value of this property is never persisted in the database.

I also tried to remove and add again the type after adding a new property but it didn't help.

Maybe it is just not possible, but this part of the addDirectMapping() javadoc about initialized descriptor and ALTER TABLE statements made me think it was:

Quote:
Allows DirectToFieldMapping (@Basic) mapping to be added to a dynamic type through API. This method can be used on a new DynamicTypeImpl that has yet to be added to a session and have its descriptor initialized, or it can be called on an active (initialized) descriptor.

There is no support currently for having the EclipseLink SchemaManager generate ALTER TABLE calls so any new columns expected must be added without the help of EclipseLink
[...]


So is that a bug, or am I just trying to do the impossible?
If I am, any idea about really dynamic entities is welcome. Smile

Thanks,
Thomas
Re: Dynamic entities: adding properties after initialization [message #891896 is a reply to message #890024] Tue, 26 June 2012 13:17 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You cannot add properties after initialization.

Initialization indexes the mapping and generate SQL, so adding properties after this would be very difficult. Also, in a concurrent system, changing the meta-data in a running system is a very bad idea.

You may be able to attempt to reinitialize your descriptor after adding the property, but this may not work for everything.

EclipseLink's JPA support allows for a MetadataSource service that can be used to redeploy new mapping meta-data into a running system. It works by deploying a new EntityManagerFactory with the new meta-data and allowing any cocnurrent threads to finish their execution on the old EntityManagerFactory.

See,
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/External_Mappings

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




James : Wiki : Book : Blog : Twitter
Re: Dynamic entities: adding properties after initialization [message #892689 is a reply to message #891896] Fri, 29 June 2012 08:46 Go to previous messageGo to next message
Thomas Gillet is currently offline Thomas GilletFriend
Messages: 14
Registered: May 2011
Junior Member
Hi James, thanks for your reply.

I take a look at the MetadataSource, and I guess you meant to use it with Extensible Entities?

But this MetadataSource only give me access to mappings, and extensible entities are all about changing the mapping of an existing field, so I don't really see how I can use that when it comes to create brand new fields.

Thomas
Re: Dynamic entities: adding properties after initialization [message #893524 is a reply to message #892689] Wed, 04 July 2012 12:59 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

A MetadataSource can provide new mappings as well as change existing ones, (can even add new entities).


James : Wiki : Book : Blog : Twitter
Re: Dynamic entities: adding properties after initialization [message #895928 is a reply to message #893524] Mon, 16 July 2012 14:12 Go to previous messageGo to next message
Thomas Gillet is currently offline Thomas GilletFriend
Messages: 14
Registered: May 2011
Junior Member
Hi James, thank you for your help, it allowed me to partly resolve my dynamic PU problem in OSGi (http://www.eclipse.org/forums/index.php/m/895890/#msg_895890).

But so far I only took advantage of the custom class loader, allowing me to generate the mapping file on the fly.
I fiddled around a little with the XMLEntityMappings class, trying to add entities without XML mapping, but I didn't manage to add anything.

Is it possible to fill an XMLEntityMappings object without any XML file?

Thomas
Re: Dynamic entities: adding properties after initialization [message #895980 is a reply to message #895928] Mon, 16 July 2012 18:02 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Thomas,

Yes, an XMLEntityMappings object can be created without reading in an XML file, but currently this object is essentially unpublished and very ugly to use directly as it was designed to be created from XML. There isn't currently any tests or examples that use it directly - please vote for bug 383818 to have the class usabilty improved and documented.

Giamma shows an example in http://www.eclipse.org/forums/index.php/t/357791/ that might help get you started.

Best Regards,
Chris
Re: Dynamic entities: adding properties after initialization [message #896173 is a reply to message #895980] Tue, 17 July 2012 13:45 Go to previous message
Thomas Gillet is currently offline Thomas GilletFriend
Messages: 14
Registered: May 2011
Junior Member
Great! Works like a charm, replaced all my clumsy XML generation by a few lines of code. Thanks a lot.

Thomas
Previous Topic:@Onetomany problems
Next Topic:@Multitenant guidelines
Goto Forum:
  


Current Time: Fri Apr 19 08:52:49 GMT 2024

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

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

Back to the top