Map entity bean to multiple databases or tables.
Can I use one entity bean to manage the same table in multiple databases. Or the same table type with diffrent names.
I want to create an application where a customer applies online for a web service. With application a new database or table will be created for the customer. There might be 1000+ customers.
I prefer to keep each customer's data in a seperate database or table.
I assume it would be better to have one entity bean manage all the data instead of 1000.
To reuse the same bean class for different tables, you can create one EJB for each table, but use the same remote interface, home interface and bean implementation class for each EJB and certainly each EJB home object will have their own JNDI name. However this assumes you have all the tables known during development time.
In your case, you want one table for each customer, created dynamically during run-time, this indicates a problem in the design. With database, you usually keep multiple customers' records in one single table, with a primary key (e.g. user id + web service id) for each row. You don't create 1000 tables on the fly just because there are 1000 customers. Then you only need one EJB, whose primary key class contains the primary key columns of your table (e.g. user id + web service id).
yilin at 2007-6-29 11:37:20 >

I have to use sperate tables, because a lot of data will be associated with a customer (company). For example:
CustomerA (database)
+Employees (table) 100+ records
+Tasks (table) 5000+ records
+Configuration (table)
CustomerB (database)
+Employees (table)
+...
CustomerC......to 1000.
Creating so many databases might be a problem. Therefore I was thinking about a tablenaming convention e.g. CustomerAEmployeesTable, CustomerATasksTable etc.
However, the problem is still: I need to specify an EJB for each table. If I cannot use one EJB, I will have to consolidate all the data into one set of tables .i.e. mixing Customers.
But typically it's rare that peopel want to create tables dynamically at runtime. Also EJB-table mapping is specified in config files (e.g. with WebLogic, you use weblogic_cmp_RDBMS.xml). That means the tables must be fixed (no more new tables) even before you start running your application.
If you worry that tables are too big, commercial RDBMS products are designed to be scalable in performance. There are a lot of DB performance tuning and optimization you can do, such as adding index to tables for fast search, increasing your DB cache, ...
yilin at 2007-6-29 11:37:20 >
