I can insert geometry data into database from my code, but I can only query the data using an SQL editor, like PGAdmin III. I can\'t retrieve geometry data back to my code.
This does not only apply to Wildfly: I was able to fix the same issue on Tomcat by moving the PostgreSQL jar from [tomcat]\webapps[WebApp]\WEB-INF\lib to [tomcat]\lib.
btw: In my case, the problem only appeared on the customer's system; our development server was OK - there was no noticeable difference between both configurations.
You need to add Postgis, hibernate-spatial and the other related libs to your Wildfly before deploying your application, this is because the hibernate that you are using is the bundled with the wildfly but the other libraries are bundled with your war, so they are using different classloaders.
If you check this code you can see that the cast is correct, and the error message make no sense, this is tipically a issue with classloaders.
To fix this issue you need to add all libs to your wildfly, to do this you can do:
cd $JBOSS_PATH/modules/system/layers/base/org/hibernate/main
mvn dependency:copy -Dartifact=org.hibernate:hibernate-spatial:5.0.7.Final:jar -DoutputDirectory=.
mvn dependency:copy -Dartifact=org.geolatte:geolatte-geom:1.0.1:jar -DoutputDirectory=.
mvn dependency:copy -Dartifact=com.vividsolutions:jts:1.13:jar -DoutputDirectory=.
Edit the module.xml
file to add your deps:
<resource-root path="hibernate-spatial-5.0.7.Final.jar"/>
<resource-root path="jts-1.13.jar"/>
<resource-root path="geolatte-geom-1.0.1.jar"/>
And in the dependencies tag, add:
<module name="org.slf4j"/>
Also if you are using postgresql, you need to add in the dependencies tag:
<module name="org.postgresql"/>
Use the correct version in the mvn
command to download the correct jar.