That should not be a problem if you make sure to have your data sources configured with one unique jndi-name.
Yes, the jndi name in the persistence.xml is static, but it does a name lookup and as long as your *-ds.xml maps the database to the same name, it could just work.
Just note that this presumes that only *one* *-ds.xml uses that jndi name.
I can see this point, but I have no control how the data source named and JNDI registered as they are from different products. All I can is let them tell my component what is their datasources and where are them. Now even I got these information, I have no way to inject into the EntityManagerFactory or Persistence layer.
Actually you can change the names to whatever you want.
They just have to match in the areas I have listed below.
Check your [database]-ds.xml (located in your deploy dir) and look for a tag <jndi-name>SomeName</jndi-name>.
That is the name under which the datasource registers itself.
That name is also used in the persistence.xml located under .
Just make sure the two names are the same (copy & paste it .. trust me ;) ).
Or, maybe I am not getting it. Just to verify the setup:
You have a [database]-ds.xml in your deploy directory and a persistance.xml in your [project]/META-INF/ dir.
It is also probably also just have two *-ds.xmls in your deploy directory giving you access to the database. Just tried it and at least they both register themselves.
You can even have a per-database-level in the *-ds.xml.
Make sure the file name and the JNDI names are different then the first.
Maybe my explaination is not clear enough. The problem I am having now is my component does not know the data source JNDI name upfront until at deployment time. I can not endure other products will deploy a data source with the JNDI name exactly match what I defined in persistence.xml, but I can ask for the data source name from them at deployment time. However, there is no way I can set the data source name dynamically from persistence API.
Dumb question and not trying to be a jerk, but why do you have to wait until deployment time?
Who is the 'other products'?
So if I understand you correctly, you only supply the component and otherwise have zero access or control over the rest of the jboss?
Then that is not so good ;)
My original idea was to have you hardcode your jndi source name and then add a *-ds.xml to the deployment.
A brute force might be to write your own *-ds.xml into the deploy dir, but I have no idea if that is even possible.
I have similar issues, but I need to switch data sources at runtime.
I think we need some kind of dynamic data source system.
Sorry for the lack of help.
It's a component and could be integrate with a variety of products, but the huge data volume makes web service not a good candidate in such a case. While lack of pointing to a different data source at deployment time, it is a big gap to enable componentize in EJB3 environment. We do not expect to change data source at runtime, but at deployment time.