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.
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:
And in the dependencies tag, add:
Also if you are using postgresql, you need to add in the dependencies tag:
Use the correct version in the mvn command to download the correct jar.