Using Parancoe with Glassfish

All you need for deploying an application developed with Parancoe is a servlet/JSP container, for example Tomcat.

Sometimes you may need a full J2EE application server:
  • because your application need some AS services
  • because you ISP provide only a full J2EE AS and not a standalone Tomcat
  • ...I don’t know…. (tell me)

The opensource Glassfish could be a common choice.

The only thing you have to change is the database configuration…and of course the particularities of your application.

For example, suppose you want to configure Glassfish and your application for using a Java DB (Apache Derby) database. As this 100% Java DBMS is included in JDK 6 and in Glassfish, it could be a common growing choice.

Create a connection pool to your DB

In the Glassfish Admin Console (http://localhost:4848/asadmin/) go to Resources/JDBC/Connection Pools, and add a new connection pool.

In the first step of the wizard:


In the next step, you have to validate the connection data from the first step.

Remember to check the “Allow Non Component Callers” flag:


and the properties of your database connection. In particular the database name, username and password. You can also set the “create” connection property to “true”, for auto-creating the database, if it doesn’t exist yet.


Then click the Finish button.

Add a JDBC Resource

In the Glassfish Admin Console (http://localhost:4848/asadmin/) go to Resources/JDBC/JDBC Resource, and add a new JDBC resource using the connection pool you just created:


Now you can use this datasource in your Parancoe application.

Configure your Parancoe application

Usually all the database configuration is in the database.xml configuration file in the WEB-INF directory:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" 

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/myappDS"/>

    <!-- Derby session factory -->
    <bean id="sessionFactory" parent="abstractSessionFactory">
        <property name="hibernateProperties">
            <props merge="true">
                <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
                <prop key="">update</prop>
                <prop key="hibernate.show_sql">false</prop>

    <!-- Authomatic discovering of persistent classes -->
    <parancoe:discover-persistent-classes basePackage="com.myapp"/>


Note the JNDI name you use for your datasource it’s the same of the JDBC resource you just created.

Now You can deploy your application to glassfish and it will use that connection to your database. Of course you have also to startup your Java DB server.

Posted by Lucio Benfante on Wednesday, July 25, 2007