Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Add entities programmatically
Add entities programmatically [message #1233653] Mon, 20 January 2014 07:50 Go to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hey all,

with hibernate i can add entities programmatically this way:

sessionFactory = new AnnotationConfiguration()
 .addPackage("test.animals")
 .addAnnotatedClass(Flight.class)
 .addAnnotatedClass(Sky.class)


Is there something similar in EclipseLink?

This question is often asked but i could not find a satisfing answer. One answer said Dynamic JPA could be a solution but the description says:
"map relational tables to virtual classes which are created dynamically at runtime"
My classes are not created dynamically, they are already existing, but have to be registered at the entityManager.

Thanks for any help in advance,

Thomas
Re: Add entities programmatically [message #1234628 is a reply to message #1233653] Wed, 22 January 2014 12:17 Go to previous messageGo to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
Hey all,

ok maybe i try to ask another way:

I have a persistence bundle "P" which contains my JPA persistence.xml and of course a persistence service using an EntityManager to persist and load data from my database.

In addition i have two bundles "A" and "B" which contain JPA annotated pojos which i want to store.

How can i register the classes of bundle "A" and "B" at the entitymanager without having them defined in the persistence.xml which would crash the modularity of my application.

Note that i´m using EclipseLink.

Thanks alot for all advices, hints and so on.

Greetz
Thomas
Re: Add entities programmatically [message #1234809 is a reply to message #1234628] Wed, 22 January 2014 21:39 Go to previous messageGo to next message
jason zhang is currently offline jason zhangFriend
Messages: 30
Registered: July 2009
Member
How about composite PersistenceUnit ?
Re: Add entities programmatically [message #1234976 is a reply to message #1234809] Thu, 23 January 2014 09:14 Go to previous messageGo to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
As i understood the composite persistence unit is mainly for using different database. The requirement to define the Plugins (or more concrete: jar files) "A" and "B" in the composite persistence unit crushes the modulartiy again...

Anyway thanks for the hint.
Re: Add entities programmatically [message #1235150 is a reply to message #1234976] Thu, 23 January 2014 17:14 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Yes, you can dynamically change the persistence unit using a metadata source to add in what is needed: http://wiki.eclipse.org/EclipseLink/Examples/JPA/MetadataSource
With this, you can define your own Metadata source that can return your classes from outside the persistence unit. The metadata source is akin to an orm.xml file and is processed about the same time, so you would only need to list the classes and they will then get processed regularly.

This feature ships with an implementation that will load orm.xml files, but I have seen others post more dynamic implementations I just don't have any links or examples handy.
Previous Topic:Got PropertyException when using MOXy
Next Topic:MismatchedTokenException
Goto Forum:
  


Current Time: Sun Nov 23 09:00:59 GMT 2014

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

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