GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes Adding new Entity Bean in the existing application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Adding new Entity Bean in the existing application" Watch "Adding new Entity Bean in the existing application" New topic
Author

Adding new Entity Bean in the existing application

Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
Hello Folks,
I have one application which contains 40 Entity Beans and all are deployed as CMP. This application is devekloped by another developer. Now there is new requirement for which I have to add a new Entity Bean in this application.
So, what will be the beast choice for me either CMP or BMP and why? Does CMP, BMP combination in one single application is allowed?
- Dhananjay


Just like you, struggeling to get the right solutions!<br /> <br />Sun Certified Java Programmer 1.5<br /> <br />Target - SCWCD
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
I did this about 2 weeks ago with a similar-sized application. Our application has 52 CMP entity EJBs. In a nutshell, it can be done but not, however, with the IDE I am using (WSAD v4.0.3). Basically, there is NO way to do this with the WSAD v4 IDE. I was told (by IBM WSAD Support), however, that IBM has added this capability in WSAD v5 (which does me absolutely no good whatsoever).
I think IBM expects you to re-create the schema and re-map everything when adding a new table, at least in WSAD v4. However, this was not a viable option in our case because another quirk of WSAD v4 is that it renames foreign key fields (and we have a ton of those in our database) when creating the schema. Therefore, I had to choose my poison: either, create a new schema and manually change all the foreign key field names or, manually edit the XML files to add the new table.
I chose to manually modify the XML files WSAD uses for CMP mapping. It is a painstaking and tedious process but it can be done. Eventually, I was able to add the new table successfully (but it took me almost a day to do so).
As for my opinion of CMP entity beans (and I am sure there will be dissenters), I don't think they're work the paper the specification is written upon. IMHO, a well-written BMP entity bean is much easier to maintain, if only because IDEs, e.g. WSAD, do not allow you to easily manipulate CMP entity beans once you have created them.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Jay, my guess is that you posed the question to technical support in a way that they didn't really understand what you wanted to do. If you have an application from another developer with CMP and the schema is already created (I'm guessing with a top-down mapping, which is the only way in which a schema can be created -- otherwise you're picking it up) then it's really not that hard to add another CMP. Adding the CMP itself takes a matter of moments. Then you have two options:
(1) Do another top-down mapping. As you said, this generates some foreign key names, but in fact, it's not hard to go into the RSC and change the names to whatever you want...
(2) Simply go into the RSC and add another table manually with the tool, not by editing the file. (making this a meet-in-the-middle mapping). Then go into the map.mapxmi editor and create the mapping to the new table for the new bean. Take the DDL for that table alone and manually create the table on the database. Then regenerate the code, and everything should be copacetic.
What were the issues that caused this to be such a problem for you?
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Vikalp Singh
Ranch Hand

Joined: Dec 29, 2002
Posts: 50
even now i am working for the same type of the application..
where i have 40 odd old entity and 20 old session beans.
I am writing the new entity beans, which will not effect my old entity beans , and even in my new session beans i am using old entity beans.
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Kyle,
Your response has left me really confused. First, what is RSC? I did a search on Google and I believe you are referring to Relational Schema Center (which makes sense in this context). However, if I search the WSAD Help for RSC or Relational Schema Center, there are NO entries. Further, I have never seen anything remotely resembling what you are talking about in WSAD (v4.0.3).
You are correct in that it is easy to add a CMP (I assume you mean the entity bean classes and interfaces) to an existing EJB project. As long as it is correctly declared in the EJB deployment descriptor, it will appear on the Enterprise Beans side of the EJB to RDB mapping editor. The problem is to create a table so that there will be a corresponding entry on the Tables side of the mapping editor so one can map the EJB to the RDB.
In order to create one, there needs to be a table entry for the new table in the .dbxmi and the .schxmi files that WSAD maintains for CMP entity beans to reference the new .tblxmi file. If you attempt to open an editor on either the .dbxmi file or the .schxmi file, there is no option to add a new table. Therefore, I concluded that the only way to add a table was to do so manually.
Also, regarding the foreign key fields, it was not feasible, in my opinion, to rename those fields again. Understand that there are approximately 120 foreign key fields in these 52 tables. To generate a new schema, rename these fields, and remap the fields again is just asking for trouble when these fields are already named and mapped correctly. I agree that it may not be hard to change these names but it sure introduces a lot of potential for error.
I would agree with you that this would be fairly easy if one could easily add a table to the mapping editor but I don't see anything in WSAD v4.0.3 that allows me to do this. If an RSC is present in the tool, it is buried in the menus and exists without documentation.
[ February 06, 2003: Message edited by: Jay Damon ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Sorry, RSC is the Relational Schema Center, which is what we generally call the Data Perspective and all it's associated views.
Do this. Open the Data Perspective. Switch to the "Data" View. Open your EJB project, Open the Schema folder, and open the "schema" (the disk icon) and select the "schema name" (NULLID or whatever else you used). Pick the "Tables" folder. Pop up the context menu. Select "Add new Table".
Voila! Walk through the wizard. You've just added a new table to the schema -- now as I said earlier, this is a meet-in-the-middle mapping now, so you have to manually add the columns to this table to match what you want in the database...
Kyle
P.S. In working through this I'm seeing a (possibly unrelated) bug in the code generation -- I'll try to track this down tomorrow. However, my basic steps still hold.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
As for the "renaming" foreign keys -- here's a trick -- the foreign key names don't matter if you don't export them to the database; the names aren't actually used in the code. Just do your modifications to the database ON the database and work from there...
Kyle
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Excellent! This is what I needed 2 weeks ago. However, it still appears that it would have had to make some manual modifications to the .dbxmi and .schxmi files. For EVERY table I add this way, it assigns an alias of RDBTable_1. Is this the bug you are speaking of?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Yes, I think that's the root cause of the bug (which actually first evidenced itself in code generation). I'll have to verify this though -- I'll want to talk to development about this.
Kyle
 
GeeCON Prague 2014
 
subject: Adding new Entity Bean in the existing application