Glassfish SunOne Toplink Postgresql

Administration of Glassfish and SunOne

Glassfish is the “open source release” of the SunOne application server. The administration interface is available on a different port.
http://localhost:4848/
The default user and password is admin and admin.

Setting up a PostgreSQL connection pool.

Copy the database driver to SERVER_HOME/domains/domain/lib/ext and restart the server.

In the administration area click on resources → jdbc.
First you must set up a connection pool and then a datasource referencing the pool.
I created a ConnectionPoolDatasource and used org.postgresql.ds.PGPoolingDataSource. Don’t forget to add properties add the end of the dialog.

Toplink issues

The Toplink version coming with SunOne 9 and Glassfish 1 has issues with PostgreSql.
You can find a newer version at http://glassfish.dev.java.net .
After running the installation script you can find two jars in a subdirectory. Replace the old versions of these files in the SERVER_HOME/lib directory.

Informations about configuration options can be found at the following website.
http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-extensions.html

Deployment issues

I used log4j in my EJB 3 project. As this jar was not available I got a large stacktrace. Allthough I have some experience with stacktraces and other application server, I managed to overlook the actual reason for the problem.
Read the stacktrace of this server carefully and don’t forget to scroll to the right end of the stacktrace ;-)

Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Error loading deployment descriptors for module [JpaSandcastle] — Invalid ejb jar [JpaSandcastleEJB.jar]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message driven bean.
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar.
at com.sun.enterprise.deployment.backend.Deployer.loadDescriptors(Deployer.java:362)
at com.sun.enterprise.deployment.backend.AppDeployerBase.loadDescriptors(AppDeployerBase.java:327)
Referencing EJBs from a Web project
The JBoss application server does allow to reference a Session Bean from a Web project without any further configuration. This is not possible in other application server including Glassfish and SunOne.
To access the Session Bean by the local interface, I had to declare a local name for my EJB in the web.xml of the web project.

pre.

sandcastleServiceName
Session
de.laliluna.sandcastle.SandcastleServiceLocal
SandcastleServiceBean

Now, I could get a refernce to the bean by calling.
pre.
Context context = new InitialContext();
sandcastleServiceLocal = (SandcastleServiceLocal) context
.lookup(“java:comp/env/sandcastleServiceName”);

Alternatively you can use the following annotation in front of a class.
pre.
@EJB(name=“sandcastleServiceName”, beanInterface=SandcastleServiceLocal.class)

Summary

You will find the complete example in my German book and a little bit later in the english version available at shop.laliluna.de.