Chapter 7. Configuring Persistence

The ToDo application is an EJB-based J2EE application, and JBoss deployed it with no container-specific configuration required. We’ve pulled back the curtains on the database layer and on security, and now it is time to pull back the curtains on the CMP entity beans and see how to customize their persistence.

Managing Schema

When you deployed the ToDo application, JBoss created the tables required by the entity beans. This is JBoss’s default behavior, but JBoss can be even more helpful during the stages of development when your beans are more volatile and are undergoing constant change.

When your entity beans change, your database schema also has to change. It’s great that JBoss creates the schema for you, but what happens when you need the schema to change? You could delete the tables from the database and redeploy the application to force JBoss to re-create the tables.

Note

Keeping the database schema in sync with changing beans is always a huge drain on productivity.

Fortunately, you don’t need to do anything quite so heavy-handed. JBoss provides several options for schema management. We’ve seen automatic schema creation so far, but JBoss also provides automatic schema deletion and migration options, if you ask for them.

How do I do that?

JBoss provides three schema management flags: create-table, remove-table, and alter-table ...

Get JBoss: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.