Getting the HSQLDB in JBoss

Category: JBoss

1:33 AM, Mon, Jul 30 2007

Controlling a database requires a database console. There is no substitute. In Postgres we have pgAdmin and of course psql from the command line.

There is no CLI for Hypersonic DB (HSQLDB) but there's an easy way to get console access. Go to the http://localhost:8080/jmx-console/ URL, assuming that your JBoss development installation is on localhost. Find the line that says Hypersonic, like this:

database=localDB,service=Hypersonic

Click on the link. Find the void startDatabaseManager() section and click on the Invoke button. The HSQL Database Manager pops up:

HSQLDB manager

Resetting Hypersonic DB: HSQLD saves its state on disk. During development, entity definitions change, and sometimes it is necessary to reset HSQLDB to its raw state (no table definitions, no data). This is easy to do:

rm -rf server/default/data/hypersonic

from the JBOSS directory, while the server is shut down. All data are cleared. You can see the data stored by looking in the server/default/data/hypersonic/localDB.script file.

Another topic: I am trying to use JBoss Seam 1.2.1 with JBoss AS 4.2.1. At this point, everything is working, except the security features. Looking at the Seam code, it has dependencies on Sun's Expression Language reference implementation in org.jboss.seam.util.EL and org.jboss.seam.jsf.SeamELFunctionMapper. These result in exceptions like this:

Caused by: java.lang.NoClassDefFoundError: com/sun/el/ExpressionFactoryImpl
        at org.jboss.seam.util.UnifiedELValueBinding.(UnifiedELValueBinding.java:18)
        at org.jboss.seam.security.Identity.evaluateExpression(Identity.java:506)
        at org.jboss.seam.security.Identity.checkRestriction(Identity.java:149)

when using @Restrict or the Seam security UI controls. We are waiting for information on this.

Update 1: Indeed it is a bug. A JIRA entry has been filed. Hopefully this will be fixed quickly.

Update 2: With help from Michael Yuan, author of the most helpful JBoss Seam book, we found a solution. Put the el-ri.jar file in the EAR and add it as a module in application.xml. Do not put the el-api.jar in. This solves the problem. Seam security annotations now work, both in classes and in Facelets pages.

Note that, with JBoss 4.2, JAR files can be added to the lib directory of the EAR file, and it is not necessary to list them as modules in application.xml.

Seam shouldn't have any more dependencies on the Sun Expression Language reference implementation, so this is a bug, and I assume it will be fixed in a maintenance release.

I consider this to be a bug in the Sun Reference Implementation, also. Impl-type classes should not be marked public. They should have default access, which is package-private. Joshua Bloch's excellent book Effective Java Programming Language Guide explains this. Anyone who is serious about programming in Java should read Joshua Bloch's book.

Update 3: The fix doesn't work for UI elements like rendered="#{s:hasRole('admin')}". I think there is a classloader conflict. Further testing shows it works when the page is rendered by clicking a navigation link, but does not work when the page is displayed after an action is invoked in a component. It gives an exception that Function 's:hasRole' not found. Presumably this will all be fixed in the next release of the Seam 1.2 series.

The work-around in this case is simple: don't use the Seam hasRole function in the UI. Instead, make it look at the user object directly, like this: rendered="#{currentUser.admin}", where there is a boolean isAdmin() method in the User class. Not as elegant or clean, but it avoids the bug.