Coudn't you just move the beans into a different jndi directory ?
think that might work
Wessel de Roode
I realize that I'm not giving enough information right now for you to actually DO what I suggest, but I might be able to help with some details if you are interested in this approach.
In JBoss, you can use XML files in the \deploy directory to declare datasources, for example, a file called mysql-ds.xml might contain the following:
<datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <connection-url>jdbc:mysql://localhost:3306/test</connection-url> <driver-class>org.gjt.mm.mysql.Driver</driver-class> <user-name>root</user-name> <password></password> </local-tx-datasource> </datasources>
This file declares a My SQL database called "test" and gives it a JNDI name of "MySqlDS".
It seems to me that you could create two files like this one. Each file would declare a different datasource and associate a different JNDI name. I think you might even be able to declare BOTH in the same file as there is a "datasources" node but I'd have to check on that.
Anyway, if you have 2 datasources each with different JNDI names, you could use two copies of your EAR, each referring to the different datasource's JNDI names.
The question you asked about using different context roots doesn't seem to solve the problem of using different databases. Declaring different datasources with different JNDI names might.
Does this approach sound interesting to you?
Thank you for your replies.
I tried deploying two different EAR files with two different datasources. The two EAR file has one bean that have the same name. When I tried to deploy it on the same machine, it returned an error
For my problem, since the database schema is the same, I would need to rename all my beans and this could easily lead to maintenance issues.
For now, I asked my manager if there was another machine where I can install JBoss and keep the EAR files separate. This way the URL would become:
In the jboss.xml file there is a "loader-repository" element designed to permit two EARs with similar contents to be deployed without interference.
The modules inside an application often contain compiled Java classes. EJB-JARs always have classes in them. Maintaining uniqueness among class names across an entire application server can be managed with strict enforcement of naming structures among the developers. In general, however, it is probably best to ensure that the Java classes contained inside an EAR or its modules will not interfere with other classes in other applications and modules that have the same names.
For example, it is possible for two different applications to have classes with the same name. In one application, there may be a Java class named "com.spoonware.training.CustomerBean". In another application that also deals with products, there could be another Java class with the same name. If these classes are not scoped at the EAR level, they are automatically scoped at the server level. As a result, these two applications will interfere with each other. It is common for this situation to exist when multiple versions of the same application are deployed on a test or development server.
To prevent this interference, the "loader-repository" descriptor must be added to the jboss.xml for each application. For example, assume that the applications are found in two EARs: customerApp1.ear and customerApp2.ear. Both applications have ejb-jars which contain numerous Java classes with names in common between the two EARs. To ensure that each set of classes do not interfere with each other, the server-specific deployment descriptors should have the following entries respectively:
<jboss-app> <loader-repository> customers1.spoonware.com:loader=customerApp1.ear </loader-repository> </jboss-app>
<jboss-app> <loader-repository> customers2.spoonware.com:loader=customerApp2.ear </loader-repository> </jboss-app>
The value of this parameter has two parts separated by a colon. To the left of the colon, the value does not matter as long as it is unique on the application server and is a valid JMX ObjectName. The part to the right of the colon must be in the format "loader=earfilename" where "earfilename" is the name of the current EAR.
I don't for sure if this approach will solve your conflicts problem but I've done it this way in the lab in the past and it solved mine.
Give it a try and let us know what you get.
Oops! It looks like I made a mistake. In the above document, I should have said that the <loader-repository> stuff goes in the "jboss-app.xml" file in the META-INF folder and not in the jboss.xml file.