I have set up a JDBC pool with postgres. These are the basic steps.
You need to place a postgres-ds.xml in the deploy directory which looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://localhost/dbname</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
</local-tx-datasource>
</datasources>
Before deploying this file make sure that the jdbc libraries are in the classpath. You can get the file from here:
http://jdbc.postgresql.org/download.html
Put the jdbc driver file in server/default/lib directory and restart the server. Then deploy the postgres-ds.xml file.
Then when that is working you can set up the jndi with a jboss-service. You create a sar file with the following information in the jboss-service.xml file which is placed in <sar filename>/META-INF
<server>
<mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<!-- <depends>jboss.jca:service=RARDeployer</depends> -->
<!-- <depends>jboss.jca:name=PostgresDS,service=LocalTxCM</depends> -->
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">com/camp/common/accounting/ApplicationAccounting.hbm.xml,
<attribute .....next resource file......../>
<attribute name="JndiName">java:/CAMP/HibernateFactory</attribute>
<attribute name="Datasource">java:/PostgresDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="TransactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="SecondLevelCacheEnabled">true</attribute>
<attribute name="QueryCacheEnabled">true</attribute>
</mbean>
</server>
Note that the datasource for the jboss-service file is the same as the name of the datasource you gave it in the first postgres-ds.xml file.
You also need to place all the hbm.xml files and their corresponding .class files in the .sar file as well. Once that is created you should be able to deploy it.
Then, to create a sessionFactory do something like the following:
Context ctx = new InitialContext();
SessionFactory sessionFactory = ((SessionFactory) ctx.lookup("java:/CAMP/HibernateFactory")).openSession();
Hope that helps.
Cheers
Tom