Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » [Solved]Recalibrate EMF or EM during runtime - database location
[Solved]Recalibrate EMF or EM during runtime - database location [message #964686] Tue, 30 October 2012 18:14 Go to next message
Scott Hull is currently offline Scott HullFriend
Messages: 32
Registered: July 2012
Member
This is a shot in the dark. I do not think this can be possible, but I wanted to see if anyone has figured out a way to make this work. This topic does coincide with dynamic PUs, but not with editing the managed types or the entities.

Hi, I wanted to figure out if there was a way to change the database location during runtime (create a new one if necessary). Here are the restrictions currently within my application:

1.) The persistence.xml file can not be edited during runtime.
2.) The factory is automatically given based on the xml requirements with a pre-determined database location.
3.) The factory is created within a PDE and Dynamic Service call.
4.) You can assume that the database has not been created in its new location. However, the preset database can be created.
5.) The factory can not be destroyed and re-created (yes, the hard part).

In other words, I am looking for a way to change value of the property(and only this property):
javax.persistence.jdbc.url

Here are some things I have tried:
1.) Create the EntityManager with a modified properties file from the static factory(new location of database). Although this does create the database, it does not establish the mapping.


My overall goal is to have the product allow the option to specify a database location during runtime. If I have to restart the application in order for this to be achieved successfully, that is acceptable.

I understand that the easiest way to solve this problem is to recreate the factory instance with a modified PU, but that is not an option at this time.

I am open to some pretty creative ideas at this point.

Thanks

[Updated on: Wed, 31 October 2012 12:11]

Report message to a moderator

Re: Recalibrate EMF or EM during runtime - database location [message #964702 is a reply to message #964686] Tue, 30 October 2012 18:31 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 216
Registered: July 2009
Senior Member
Hi Scott,

If your use case is that you simply want to be able to specify the database for your EMF at runtime then the best way to do that is to *not* specify the jdbc properties in the persistence unit but then specify them at runtime using the EntityManagerFactoryBuilder. That is precisely what the builder is for. See this documentation section for details on how to do that.

Using the builder will get you to the point of creating a single EMF, but with the database being configured at runtime. If you are wanting to create an EMF, use it, and then possibly create *another* EMF to a different database then you will want to look at the feature that allows multiple EMFs from the same persistence unit. See this documentation section for more information on how to do that.

Hope this helps,

-Mike
Re: Recalibrate EMF or EM during runtime - database location [message #965660 is a reply to message #964702] Wed, 31 October 2012 12:10 Go to previous message
Scott Hull is currently offline Scott HullFriend
Messages: 32
Registered: July 2012
Member
Thanks Mike. I thought this was the case.
Previous Topic:[Solved]Issue with Gemini - "Object is not a known Entity Type"
Next Topic:[Solved]Gemini - Maven-tycho build works on some machines, but not others.
Goto Forum:
  


Current Time: Sun Nov 23 22:45:18 GMT 2014

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

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