The only commercial product in my toolbox is Visual Paradigm, a professional UML and modeling tool that integrates with the Netbeans IDE. If you are sincere about ERD, Use-Case and class models you should look at it. The available Netbeans plugins for UML could not convince me yet, too simple (but free). Visual Paradigm seems to operate at the other end, looks rather overloaded with functionality, but once you know what you want and where the function is located, you can create a nice workflow.
In this tutorial (created for internal purpose) I share the steps to create an EJB and the ERD model and let VP (Visual Paradigm) create the class source code for me.
- Netbeans 7.x
- Visual Paradigm (Professional Version)
You can download the 30 days trial, the free community edition is not sufficient.
Tutorial Part 1:
- Create EJB module ‘demoejb’
- Create the VP project file
If you have properly integrated NB and VP you should see this additional buttons
Select the file view, select the project and click the VP icon
(It makes a difference ! If you select the project in the projects explorer and click the VP icon the file gets created under /src/vpproject and the code creation fails later on, not sure if this is a feature or a bug as of VP version 5.2)
- Create a ERD diagram with our DB table layout
For this sample we will use the simple name-address sample
customer_name and customer_address (the tables are not complete, rather a base for the demo walk-through)
We use a UUID in all tables as primary key.
primary key: pk_customer_name
primary key: pl_customer_address
Create a one-to-many relationship
Click the ‘one-to-many’ tool, then drag from customer_name to customer_address, and enter:
fk_customername_customeraddress as new column for the relationship
- Create classdiagramm
Change the stereotype to entity bean for both classes
Final Class Diagram
- Synchronize with Netbeans (code creation)
Created package and classes
There is a bug in the code creation, the imports dont get properly created (as in current version 5.2)
Fix the problem manually by importing
You can check the Netbeans Settings in VP
- Add Eclipse library to project
(we need for JPA queries at a later stage)
- Create Meta Model
Just clean and build will result in meta class created.
- Create Persistence Unit ‘demoejbPU’
For now we use the default sample DB
- Create Session Bean for Entity Class
in package facade
- Final project structure
- Deploy the EJB
The tables get created (depending on your PU strategy)
- Even VP supports round-trips, means changes in the EJB class can be sync’d back to your VP project, I prefer to maintain all DB changes in VP and recreate class diagram and classes, you better dont touch the class asit gets overwritten.
- Be careful with deletions and name changes of columns, they are not ‘forwarded’ to your already existing classes (source code).
In Part 2 we will create a ZK client web application and tinker with different DB’s (Oracle and PostgreSQL). Stay tuned.