How to generate EJB3-JSF from an existing database

From IHE Wiki
Jump to navigation Jump to search



/!\ This is a warning. Generation of EJB3-JSF using JBoss Seam will create many code files, and almost all this generated code will need to be changed, because of our Gazelle needs. The code generation from an existing database is helpful only if you have many tables already existing. About this code, you could keep some parts of the generated model classes and may be some parts of the actions classes. You could also keep some JSF codes, only if you need a simple GUI to modify easily your datas (eg. GUI as Phppgadmin).

You will have to check how the junction tables generate your codes. It can sometimes make troubles, cause some junction tables doesn't need ID and are not considerated as a POJO.



If you really need to generate codes for Gazelle module using an existing database structure (tables with columns to create objects with attributes), please read the following steps.


1. First of all, you have to install JBoss Seam and JBoss Application Server on your system (If it's not installed, see Chapter 3. Prerequisites).


2. In the JBoss Seam homepath, setup the configuration for your generation project. It's easier to generate code in a temporary project, then to copy only interesting EJB3/JSF.

To configure, you have to launch in a console the command :

  • ./seam setup

A menu appears, where you have to set your parameters. Here is below an example of configuration (also reachable in the <jboss-seam homepath>/seam-gen/build.properties )


Please replace the <module-name> and <database-name-containing-your-datas-and-used-for-generation> below :

Thu Aug 30 16:24:01 CEST 2007
hibernate.connection.password=
workspace.home=/home/jchatel/workspace
model.package=net.ihe.gazelle.<module-name>
driver.jar=/usr/local/jboss/server/default/lib/postgresql-8.1-409.jdbc3.jar
action.package=net.ihe.gazelle.<module-name>
test.package=net.ihe.gazelle.<module-name>
database.type=postgres
hibernate.default_catalog.null=
database.drop=n
hibernate.default_schema.null=
project.name=''<module-name>''
hibernate.connection.username=gazelle
hibernate.connection.driver_class=org.postgresql.Driver
project.type=war
database.exists=y
jboss.home=/usr/local/jboss
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.url=jdbc\:postgresql\://localhost\:5432/<database-name-containing-your-datas-and-used-for-generation>



3. Then, it's possible to generate your project from the existing database, using the following command in a console :

  • ./seam generate-entities

The project <module-name> will be created in your workspace. You can now copy the code you need in your project, following the last recommendations (Warning above).

Needable code will be reachable in the directories :

  • <module-name>/src/model/**
  • <module-name>/src/action/**
  • <module-name>/view/**



Back to the Gazelle Developers Guide homepage.