You are here

Java EE advanced topic, shortcomings, troubles, tricks

Here is a list of issues I came across when working with Java EE (J2EE).

Limit number of EJB3 MDB instances (JBoss 4.0.5.GA)

First of all, do not fall into a trap (as me) and do not follow JBoss MDB Config WiKi, it is related to EJB 2.x. The <configuration-name> is ignored by org.jboss.ejb3.ddJBossDDObjectFactory (called from org.jboss.ejb3.Ejb3HandlerFactory.DDFactory(Ejb3Deployment di))

Use the ActivationConfigProperty "maxSession", default is 30:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(
		propertyName = "destinationType",
		propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(
		propertyName = "destination",
		propertyValue = "queue/email"),
@ActivationConfigProperty(
		propertyName = "maxSession",
		propertyValue = "1")})
public class MailerMDB implements MessageListener {

Resources

  • DLQ - Dead Letter Queue (poison message queue)
  • JBossMQ - Java Message Service API implementation by JBoss
  • ConfigJMSMessageListener - Configuration of JMS message Listener, can be used in ActivationConfigProperty annotations

JBoss EJB3/Hibernate doesn't escape table or column names (JBoss 4.0.5.GA)

The following code may cause troubles to SQL engine, because the table name or column name clashes with SQL keyword.

@Entity // PostgreSQL doesn't like "create table User ..."
public class User implements Serializable {
// HSQL doesn't like "order" in SQL query
public byte getOrder() {
...
}
}

There is no portable solution, the following code may not work, it depend on database provider. Isn't this case for database abstraction?

@Entity
@Table(name="\"User\"") // PostgreSQL OK, HSQL bug
public class User implements Serializable {
@Column(name="`order`")// PostgreSQL bug, HSQL OK
public byte getOrder() {
...
}
}

JBoss and HSQL (JBoss 4.0.5.GA)

JBoss 4.0.5.GA is distributeds with HSQL database. Unfortunately the shipped version is quite old (which version?) and has many bugs. The HSQL 1.8.x works fine with JBoss, must place the jar in server/default/lib folder.

The HSQL is tiny SQL engine written in pure Java and it has severe limitations and default settings, that may not be good for your application testing. For instance, prior to 1.7.2, all table column type definitions with a column size, precision or scale qualifier were accepted and ignored. The 1.7.2 default settings still ignores sizes.

Connection URL with enforced size property

For in memory database:
jdbc:hsqldb:mem:localhost;sql.enforce_strict_size=true
For hsql database in JBoss the hsqldb-ds.xml must be changed (specifying property in connection string doesn't work). It is a hack but should work, see HypersonicDatabase.java. As an alternative, use <new-connection-sql>:
<mbean code="org.jboss.jdbc.HypersonicDatabase" 
name="jboss:service=Hypersonic">
...
<attribute name="Database">default;sql.enforce_strict_size=true&lt/attribute>
</mbean>

Resources

Tomcat 5 logging

I have always troubles to setup tomcat (conatiner) logging correctly. The default installation of Tomcat 5.0.28 on Gentoo doesn't log, catalina.out says:

log4j:WARN No appenders could be found for logger (org.apache.catalina.startup.Embedded).
log4j:WARN Please initialize the log4j system properly.		

Here is a checklist for succesfull logging:

  • Place commons-logging.jar to {tomcat}/common/lib folder
  • Place log4j.jar to {tomcat}/common/lib folder
  • Place log4j.properties (or log4j.xml) to {tomcat}/common/classes folder
  • Add the {tomcat}/common/classes folder to classpath in {tomcat}/bin/catalina.sh
  • (optionally) Add -Dlog4j.debug=true to {tomcat}/bin/catalina.sh, this will show debug messages from log4j startup.

Resources