|
Re: REALLY dynamic database connection settings [message #698613 is a reply to message #698420] |
Tue, 19 July 2011 20:02 |
Michael Keith Messages: 243 Registered: July 2009 |
Senior Member |
|
|
A persistence unit is meant to be a static configuration for persisting a set of entities. The provider needs to know the necessary bits in order to configure an EMF to connect to a datasource, create mapping descriptors, weave the entities, and so forth. This has always been an assumption of JPA.
It turns out that since the provider does not actually need to do this until the EMF is created then some of the properties, such as the connection info, can be passed in at EMF creation time instead of being defined in the persistence.xml file. However, this does not change the fact that a single named p-unit is bound to a specific datasource. If it were able to be associated with multiple data sources then how would you know which datasource you were getting when you referenced a named p-unit? An EMFB is just a way to dynamically specify the connection info at runtime without actually putting it in the persistence.xml file. It is still associated with a single p-unit.
It sounds like you are actually wanting to create a new p-unit on each call (complete with new p-unit name, etc), and that is a separate feature, one that is close to existing but does not currently exist. Please enter a bug and perhaps I can work with the EclipseLink team to see if it could be supported. There would be caveats, though, such as the fact that the service would no longer be tracked and follow the lifecycle of a particular datasource since there may be multiple data sources associated with a given EMFBuilder, etc.
-Mike
|
|
|
Re: REALLY dynamic database connection settings [message #699026 is a reply to message #698613] |
Wed, 20 July 2011 16:59 |
ephikles Messages: 3 Registered: July 2011 |
Junior Member |
|
|
Hi Mike,
thanks alot for your quick answer!!
Well, I now know you're right. I just read part of the JPA-specs: 5.3 Obtaining an Entity Manager Factory. According to the spec, Quote:More than one entity manager factory instance may be available simultaneously in the JVM. , but also that Quote:There is only one entity manager factory per persistence unit
So if I want more than one EntityManagerFactory in order to access a different datasource, I also need a different punit for the EMF.
That means I either have to go the hard way and find a way to create my own EMFs, which seems to be more than painful, or I have to come begging to you.
Gemini JPA, as it is, creates an EntityManagerFactoryBuilder. Sadly it's bound to the first EntityManagerFactory that is created by it. It would be nice if I could use the EMFB to create, as mentioned above, "more than one entity manager factory instance [to] be available simultaneously in the JVM". And I accept the fact that these EMFs must be for different persistence units; where, in my case, "different" would be different in name and datasource-binding.
I'm well aware that my idea is a break in concept for your EMFServiceProxyHandler which is bound to a punit and an EMF, at least as soon as the latter is created.
But I'm convinced that for someone who is as greatly blessed with skill as you, it won't pose much of a problem to make the gemini jpa project this little bit more flexible and hence usable in a multi-datasource environment!
Thank you for reading my gibberish! A bug report, if you still want one, will come tomorrow..
..here it is: Bug ID 352708 (i'm not allowed to post links yet )
[Updated on: Thu, 21 July 2011 08:36] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04879 seconds