<< How to make GlassFish's embedded Derby listen on a socket | Home | Monitoring GlassFish with jconsole >>

Some stumbling blocks

A few "remind-myself" notes about various stumbling blocks that I encountered while writing my first Java EE code for GlassFish:
  • You need $GLASSFISH_HOME/lib/javaee.jar in the classpath when compiling.
  • The JMS Destination Resource must have the property Name=PhysicalQueue, or Name=PhysicalTopic for a topic.
  • Resouce injection by annotations doesn't work for arbitrary classes or JSP sources. It only works for container managed components like EJBs, servlets, servlet filters, JSP tag handlers, application-client "main" classes,
  • The server log is spammed with a multitude of these messaging exceptions:
    "com.sun.messaging.jmq.io.Packet cannot be cast to com.sun.messaging.jms.ra.DirectPacket"
    Follow the instructions here to have JMS run in a separate process. Note: this problem has been fixed in the GlassFish v2.1 beta.
  • The web-app XML schema for "web.xml" must be version 2.5 for annotations to work.
  • For injection to work in application clients, the injection variables must be static. And in order to inject EJBs the client must be packaged in an EAR file and declared in "application.xml".
  • Injection variables cannot be static in servlets and filters.
  • Persistent entity classes must be placed in jars under "lib" in the EAR file.
  • Servlet and filter objects should not have EntityManagers as instance variables, since EntityManagers are not thread-safe. Instead, either use an EJB as an instance variable and let the EJB access the EntityManager, or use EntityManagerFactory to create a temporary EntityManager and manage the transactions yourself.
  • Any webapp that requires login needs a "sun-web.xml" that declares <security-role-mapping>, otherwise no one is allowed access. Or if the webapp is packaged in an EAR file, the same mapping can be declared in "sun-application.xml". Also, the <realm-name> in "web.xml" cannot contain space characters.
  • If you change the admin password, asadmin login is needed to update the stored credentials in ~/.asadminpass.
  • Use @TableGenerator annotation for a portable way to generate primary keys for persistent @Entity objects. The generated keys are filled in by the first call to EntityManager.persist(), and the new key is committed by EntityManager.flush().
  • Log Toplink-generated SQL statements by adding the following property under <persistence-unit> in "persistence.xml":
    <property name="toplink.logging.level" value="FINE"/>



Add a comment Send a TrackBack