Hiya,
Ok. Built Entity bean. Deployed in jar. After some fiddling that is. My
situation is this; I have four environments. A "dev", "test", "stage" and
"production' environments. (Explanation as to why is available on demand.
Sigh) Each consists of at least one web server and a database server. The
"web" component in each environment is identical. The database schema on
each database server in each environment is identical. The data differs. For
example; I have an "Agent" table on each DB. The schema is identical, but
they have different data in them.
I have to build my "local" app running on my desktop to be able to
communicate with any of the four database servers. So, my data-sources.xml
has four entries:
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="MSSQL - SmartOffice (DEV)"
location="jdbc/SmartOfficeDevCoreDS"
pooled-location="jdbc/SmartOfficeDevPooledDS"
xa-location="jdbc/xa/SmartOfficeDevXADS"
ejb-location="jdbc/SmartOfficeDevDS"
connection-driver="sun.jdbc.odbc.JdbcOdbcDriver"
username="SmartOffice"
password="SmartOffice"
url="jdbc:odbc:SmartOfficeDev"
inactivity-timeout="30"
schema="database-schemas/ms-sql.xml"
/>
Where the "DEV" part gets changed to TEST, STAGE and PROD for each of the
other environments. (Plus users and passwords of course). The ODBC sources
are all in existence. I checked it. A JSP page on my desktop can use each of
the datasources independently to access the tables on each DB using plain
beans and raw JSP sql calls. No probs. Kewl in fact. But I want to use EJBs.
So I build this Agent Entity EJB. Ant compiles it and orion hot deploys.
Kewl. I then try to use it in a JSP page and suddenly realize that I have to
define the datasouce in the ejb-jar.xml file otherwise it will be using
Hypersonic. Oh, ok I say and start to edit it. Then insanity and a
connuption fit strikes. The ejb-jar.xml file allows the use of the
<resource-ref> tag. I started to read up on it, then realised that I can
specify only one datasource in it. So I have to use four Agent EJB entries
where the <resource-ref> is different in each case. Then I realise I can't
do that because the EJB name must be unique. Apparent stalemate.
I need to be able to allow the user to use the Agent Entity EJB to point at
any of the DEV, TEST, STAGE and DEV databases. I understand what an entity
bean is BTW. It just seems a bit silly to create an AgentDev, AgentTest,
AgentStage and AgentProd version where they are all identical codewise and
have code in the JSP flip from one to the other. My "plain" beans use a
"setSource(javax.sql.DataSource)" method to allow me to control which
database they are actioned against on the fly from within the JSP. I can't
seem to find any way to specify how to do the same from the containers
perspective though. It's looking like I have to use BMP instead of CMP.
Rats. Sort of defeats the purpose.
More mystifying is that I found that no matter what you do to the
ejb-jar.xml, you cannot set any other datasource than the first one in the
datasources.xml (Hypersonic in my case). You have to manually go to the
application-deployments/<app>/<app>-ejb.jar directory and edit the
orion-ejb-jar.xml file by hand to change the:
<enterprise-beans>
<entity-deployment
name="Agent"
location="Agent"
wrapper="AgentHome_EntityHomeWrapper5"
table="Agent"
data-source="jdbc/HypersonicDS"> <<- always get this
To:
<enterprise-beans>
<entity-deployment
name="Agent"
location="Agent"
wrapper="AgentHome_EntityHomeWrapper5"
table="Agent"
data-source="jdbc/SmartOfficeProdDS"> <<- your datasource
name
Each time you deploy. I **MUST** be doing something wrong here. This can't
be right. Has anybody done anything similar in the past? I've read just
about every damn book on this and scoured the web to no avail. Either I'm as
dim as a box full of broken light globes, or I'm in overload (I didn't know
J2EE from a bar of soap 4 weeks ago), or I'm not getting something
fundamental that everybody else seems to take a-priori.
Help! Arggghhhhhhhhh...
Kimbo
Senior Web Developer
Peakhour Pty Ltd
http://smartoffice.com.au
http://peakhour.com.au
http://www.geocities.com/kimmie_scott
winmail.dat