[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

J2EE CMP Entity Beans and Multiple Database Instances



We are working with a single JBoss app server instance against several 
database instances. Each db instance has the same schema but different data. 
A user's login determines which database they are working against. 

We have one CMP entity bean class defined for each table that we work with, 
but we have separate entries in the ejb-jar and jaws.xml files for each 
database instance that the bean works against. For example, we might have 
MyEntity as the class, but for db1 have an ejb-name of db1.MyEntity, and for 
db2 have an ejb-name of db2.MyEntity. Likewise the JNDI names are different, 
something like ejb/db1/MyEntity and ejb/db2/MyEntity.

We are using stateless Session bean facades to access the entity beans on 
behalf of client requests. The Session bean facades need to know which 
database the current user session is working with so they can invoke the 
correct entity bean instance. One way we thought of to accomplish this was to 
use a Factory approach, and use a Factory to instantiate the facade and hand 
it to the client. To use a factory concisely, we extend the EJBObject, 
EJBLocalObject, EJBHome and EJBLocalHome interfaces so that we have a means 
to set the database name on the session bean before handing it off to the 
client, who will then cast it to the appropriate type.

This all works OK, but when deploying a jar with these extended EJB interfaces 
causes the JBoss verifier to spit out warnings that the create() methods 
don't match the particular return type for the session bean facades. This 
occurs because we are using the create method in our extended interfaces so 
we can create an instance of the session bean and invoke the 
setDatabaseName() method. Remember that these are stateless session beans, 
therefore can only have the create() method with no parameters. While the 
verifier warnings are annoying, things work OK. 

I was wondering if others out there had faced this issue and how they had 
solved it? Are there better approaches than the factory for this type of 
thing? Has anyone worked with multiple database instances at the same time, 
all with the same schemas?

Thanks for any input or insight.

Ron Cordell