tirsdag den 6. november 2007

Generate your webapplication with JBoss Seam from an existing MySQL database (at least some of it)

JBoss seam is a nice framework. Code is relatively simple. It can be setup using a simple tool "seam-gen" and basically works out of the box.

But it's perhabs still a bit too new to be used in real life?

Let's try it:

My setup:
  • OS: Mac OS X (10.4.0) - macbook with 1.5 GB ram
  • DB: MySQL 5. something
  • Java: JDK 1.5
How to use seam-gen to generate a basic webapplication from an existing database.

Step 1)
  • Install JBoss seam and JBoss itself.
    • I'm using:
      • Jboss-4.2.2.GA
      • JBoss-seam-2.0CR3
      • MySQL
  • Go to the seam home dir.
  • Run the following set of commands:
./seam setup
./seam create-project
./seam generate-entities

What I got was a running application that could be opened in eclipse and Netbeans with EJB3 java classes, EntityHome classes, JSF views, editors and lists of all the entities in the database.

Good stuff:
  • It is a really good starting point for a brand new application (if the database is build up front)

Problems I found:
  • Whenever the tables in the database contains blobs or byte[] (bytearrays) it causes problems.
Disappointments:
  • The editors created disappointingly enough didn't make it possible to choose the "One" side in a ManyToOne relationship.
  • The String based properties were all to be edited in a textarea.
Questions:
  • Why is it not possible to create views from existing EJB3 entities?
    • Seams not to be a good idea to have to generate from a database if the EJB's are allready in place.
  • What's the plans with seam-gen?
  • Is it possible to generate-entities several times while working with an application without removing or overwriting added code?
  • Where can I find a real life example of a running application. (Not the academic examples provided, but some real applications).

WHAT I DID:
Here's what I chose for my specific settings:
morten-matras-computer:~/Desktop/jboss-seam-2.0.0.CR3 mortenmatras$ ./seam setup


Buildfile: build.xml

init:

setup:
[echo] Welcome to seam-gen :-)
[input] Enter your Java project workspace (the directory that contains your Seam projects) [/Users/mortenmatras/Documents/workspace] [/Users/mortenmatras/Documents/workspace]

[input] Enter your JBoss home directory [/Applications/jboss-4.2.2.GA] [/Applications/jboss-4.2.2.GA]

[input] Enter the project name [cat2] [cat2]
cat3
[echo] Accepted project name as: cat3
[input] Select a RichFaces skin (not applicable if using ICEFaces) [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT)

[input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war, )

[input] Enter the Java package name for your session beans [com.blob.session] [com.blob.session]

[input] Enter the Java package name for your entity beans [com.blob.entity] [com.blob.entity]

[input] Enter the Java package name for your test cases [com.blob.test] [com.blob.test]

[input] What kind of database are you using? [mysql] (hsql, [mysql], oracle, postgres, mssql, db2, sybase, enterprisedb, h2)

[input] Enter the Hibernate dialect for your database [org.hibernate.dialect.MySQLDialect] [org.hibernate.dialect.MySQLDialect]

[input] Enter the filesystem path to the JDBC driver jar [/Users/mortenmatras/Desktop/mysql-connector-java-5.1.5/mysql-connector-java-5.1.5-bin.jar] [/Users/mortenmatras/Desktop/mysql-connector-java-5.1.5/mysql-connector-java-5.1.5-bin.jar]

[input] Enter JDBC driver class for your database [com.mysql.jdbc.Driver] [com.mysql.jdbc.Driver]

[input] Enter the JDBC URL for your database [jdbc:mysql://localhost/catalog] [jdbc:mysql://localhost/catalog]
jdbc:mysql://localhost/THE_NAME_OF_A_SPECIFIC_DATABASE_EXISTING

[input] Enter database username [root] [root]

[input] Enter database password [] []
YOUR_PASSWORD_HERE

[input] skipping input as property hibernate.default_schema.new has already been set.
[input] Enter the database catalog name (it is OK to leave this blank) [] []

[input] Are you working with tables that already exist in the database? [y] ([y], n, )

[input] Do you want to drop and recreate the database tables and data in import.sql each time you deploy? [n] (y, [n], )

[input] Enter your ICEfaces home directory (leave blank to omit ICEfaces) [] []

[delete] Deleting: /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/seam-gen/build.properties
[propertyfile] Creating new property file: /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/seam-gen/build.properties
[echo] Installing JDBC driver jar to JBoss server
[echo] Type 'seam create-project' to create the new project

BUILD SUCCESSFUL
Total time: 38 seconds
morten-matras-computer:~/Desktop/jboss-seam-2.0.0.CR3 mortenmatras$ ./seam create-project
Buildfile: build.xml

init:

init-properties:
[echo] /Applications/jboss-4.2.2.GA

validate-workspace:

validate-project:

icefaces-staging-copy:

initcopy:

initpoms:
[echo] Setting up dependencies
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[artifact:install] [INFO] Installing /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms/root.pom to /Users/mortenmatras/.m2/repository/org/jboss/seam/root/2.0.0.CR3/root-2.0.0.CR3.pom
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[artifact:install] [INFO] Installing /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms/parent.pom to /Users/mortenmatras/.m2/repository/org/jboss/seam/parent/2.0.0.CR3/parent-2.0.0.CR3.pom
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms
[copy] Copying 1 file to /Users/mortenmatras/Desktop/jboss-seam-2.0.0.CR3/classes/poms

copyseam:

copyseamdependencies:

copyjbossembedded:

copy-lib:
[echo] Copying Seam and depdencies to the /Users/mortenmatras/Documents/workspace/cat3/lib directory...
[copy] Copying 97 files to /Users/mortenmatras/Documents/workspace/cat3/lib
[echo] Copying JBoss Embedded configuration to the /Users/mortenmatras/Documents/workspace/cat3/bootstrap directory...
[copy] Copying 26 files to /Users/mortenmatras/Documents/workspace/cat3/bootstrap

file-copy-war:

file-copy-ear:
[echo] Copying resources needed for EAR deployment to the /Users/mortenmatras/Documents/workspace/cat3/resources directory...
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources/WEB-INF
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3
[copy] Copying 6 files to /Users/mortenmatras/Documents/workspace/cat3/resources

setup-filters:

file-copy:
[copy] Copying 11 files to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/.settings
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/resources
[copy] Copying 11 files to /Users/mortenmatras/Documents/workspace/cat3/view
[copy] Copying 3 files to /Users/mortenmatras/Documents/workspace/cat3/view
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/src/action/com/blob/session
[copy] Copying 6 files to /Users/mortenmatras/Documents/workspace/cat3
[mkdir] Created dir: /Users/mortenmatras/Documents/workspace/cat3/src/model
[mkdir] Created dir: /Users/mortenmatras/Documents/workspace/cat3/src/test
[copy] Copying 1 file to /Users/mortenmatras/Documents/workspace/cat3/src/test
[mkdir] Created dir: /Users/mortenmatras/Documents/workspace/cat3/nbproject
[copy] Copying 3 files to /Users/mortenmatras/Documents/workspace/cat3/nbproject

create-project:
[echo] A new Seam project named 'cat3' was created in the /Users/mortenmatras/Documents/workspace directory
[echo] Type 'seam explode' and go to http://localhost:8080/cat3
[echo] Eclipse Users: Add the project into Eclipse using File > New > Project and select General > Project (not Java Project)
[echo] NetBeans Users: Open the project in NetBeans

BUILD SUCCESSFUL
Total time: 3 seconds
morten-matras-computer:~/Desktop/jboss-seam-2.0.0.CR3 mortenmatras$ ./seam generate-entities
Buildfile: build.xml

init:

init-properties:
[echo] /Applications/jboss-4.2.2.GA

validate-workspace:

validate-project:

generate-entities:
[echo] Reverse engineering database using JDBC driver /Users/mortenmatras/Desktop/mysql-connector-java-5.1.5/mysql-connector-java-5.1.5-bin.jar
[echo] project=/Users/mortenmatras/Documents/workspace/cat3
[echo] model=com.blob.entity
[hibernate] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
[hibernate] 1. task: hbm2java (Generates a set of .java files)
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.Environment
[hibernate] INFO: Hibernate 3.2.5
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.Environment
[hibernate] INFO: hibernate.properties not found
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.Environment buildBytecodeProvider
[hibernate] INFO: Bytecode provider name : cglib
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.Environment
[hibernate] INFO: using JDK 1.4 java.sql.Timestamp handling
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.reveng.OverrideRepository addFile
[hibernate] INFO: Override file: /Users/mortenmatras/Documents/workspace/cat3/resources/seam-gen.reveng.xml
[hibernate] 2007-11-06 19:15:22 org.hibernate.connection.DriverManagerConnectionProvider configure
[hibernate] INFO: Using Hibernate built-in connection pool (not for production use!)
[hibernate] 2007-11-06 19:15:22 org.hibernate.connection.DriverManagerConnectionProvider configure
[hibernate] INFO: Hibernate connection pool size: 20
[hibernate] 2007-11-06 19:15:22 org.hibernate.connection.DriverManagerConnectionProvider configure
[hibernate] INFO: autocommit mode: false
[hibernate] 2007-11-06 19:15:22 org.hibernate.connection.DriverManagerConnectionProvider configure
[hibernate] INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/catalog
[hibernate] 2007-11-06 19:15:22 org.hibernate.connection.DriverManagerConnectionProvider configure
[hibernate] INFO: connection properties: {user=root, password=****}
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: RDBMS: MySQL, version: 5.0.41
[hibernate] 2007-11-06 19:15:22 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
[hibernate] 2007-11-06 19:15:23 org.hibernate.dialect.Dialect
[hibernate] INFO: Using dialect: org.hibernate.dialect.MySQLDialect
[hibernate] 2007-11-06 19:15:23 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
[hibernate] INFO: Using default transaction strategy (direct JDBC transactions)
[hibernate] 2007-11-06 19:15:23 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
[hibernate] INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Automatic flush during beforeCompletion(): disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Automatic session close at end of transaction: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: JDBC batch size: 15
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: JDBC batch updates for versioned data: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Scrollable result sets: enabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: JDBC3 getGeneratedKeys(): enabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Connection release mode: auto
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Maximum outer join fetch depth: 2
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Default batch fetch size: 1
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Generate SQL with comments: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Order SQL updates by primary key: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Order SQL inserts for batching: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
[hibernate] INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[hibernate] 2007-11-06 19:15:23 org.hibernate.hql.ast.ASTQueryTranslatorFactory
[hibernate] INFO: Using ASTQueryTranslatorFactory
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Query language substitutions: {}
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: JPA-QL strict compliance: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Second-level cache: enabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Query cache: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory createCacheProvider
[hibernate] INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Optimize cache for minimal puts: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Structured second-level cache entries: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Statistics: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Deleted entity synthetic identifier rollback: disabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Default entity-mode: pojo
[hibernate] 2007-11-06 19:15:23 org.hibernate.cfg.SettingsFactory buildSettings
[hibernate] INFO: Named query checking : enabled
[hibernate] 2007-11-06 19:15:23 org.hibernate.connection.DriverManagerConnectionProvider close
[hibernate] INFO: cleaning up connection pool: jdbc:mysql://localhost/catalog
[hibernate] 2007-11-06 19:15:24 org.hibernate.tool.Version
[hibernate] INFO: Hibernate Tools 3.2.0.b10
2007-11-06 19:15:24 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/catalog
[hibernate] 2. task: generic exportertemplate: view/list.xhtml.ftl
[hibernate] 3. task: generic exportertemplate: view/view.xhtml.ftl
[hibernate] 4. task: generic exportertemplate: view/view.page.xml.ftl
[hibernate] 5. task: generic exportertemplate: view/edit.xhtml.ftl
[hibernate] 6. task: generic exportertemplate: view/edit.page.xml.ftl
[hibernate] 7. task: generic exportertemplate: src/EntityList.java.ftl
[hibernate] 8. task: generic exportertemplate: view/list.page.xml.ftl
[hibernate] 9. task: generic exportertemplate: src/EntityHome.java.ftl
[hibernate] 10. task: generic exportertemplate: view/layout/menu.xhtml.ftl
[javaformatter] Java formatting of 64 files completed. Skipped 0 file(s).
[echo] Type 'seam restart' and go to http://localhost:8080/cat3

BUILD SUCCESSFUL
Total time: 5 seconds

1 kommentar:

SD sagde ...

nice post ^^

What web framework is the next big one?

Om mig

Odense, Denmark
A simple man with a simple life... Couldn't be better