This is in the scenario where you want JBoss to handle the datasource and transactions, for example when using injected @PersistenceContext in a @Stateless resource. I like it especially when writing REST services with JAX-RS (example code included below).
Create dir:
/modules/org/postgresql/main
Place files at these locations:
/modules/org/postgresql/main/postgresql-8.3-607.jdbc4.jar
/modules/org/postgresql/main/postgis-1.5.3.jar
Create file /modules/org/postgresql/main/module.xml with content:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
<resources>
<resource-root path="postgresql-8.3-607.jdbc4.jar"/>
<resource-root path="postgis-1.5.3.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Place files at these locations:
/modules/org/hibernate/main/hibernate-spatial-4.0-M1.jar
/modules/org/hibernate/main/jts-1.12.jar
Add this xml fragments to the resources tag in /modules/org/hibernate/main/module.xml:
<resource-root path="hibernate-spatial-4.0-M1.jar"/>
<resource-root path="jts-1.12.jar"/>
Add this xml fragment to the dependencies tag in /modules/org/hibernate/main/module.xml:
<module name="org.postgresql"/>
Finally, add this xml fragment to the drivers tag in your deployment configuration (might be /standalone/configuration/standalone.xml):
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
NOTE: Trying to use Hibernate Spatial for a specific deployment in WEB-INF/lib will result in classpath problems which is one reason for this how to...
Hello,
Thank you for the how to.
Just would like to add three things.
1 - The Hibernate Spatial can be inside your WEB-INF/lib if you don't put them as modules. If it is as modules, you have to put the Hibernate-Spatial dependencies as provided in your POM.xml using Maven.
2 - It is recommended to create a JNDI datasource via the management console or the XML File of your server (might be standalone.xml). Don't forget to verify that driver-class used is org.postgis.DriverWrapper
3 - You have to add the module org.postgresql as an explicit dependency. You can do this by using MANIFEST.MF file or the jboss-deployment-structure.xml
Example of the jboss-deployment-structure.xml
This was tested using JBoss 7.1.1 Final and JBoss EAP 6.1 Final
Just hope that this comment will help someone.