3

I am using Wildfly 10 and developing an application using Spatial Hibernate 5 with PostGIS database. I am getting the below error in runtime.

java.lang.IllegalStateException: Received object of type org.postgresql.util.PGobject 

Can anyone suggest some good tutorials as on how to use Spatial Hibernate with Wildfly 10?

3
  • Same here. Where you able to solve this yet? Commented Mar 18, 2016 at 13:45
  • Did you find a way around this, I really dont want to do that way around @Toastor suggested Commented May 18, 2016 at 20:01
  • Check this answer to find the solution: stackoverflow.com/a/46222613/1126380, basically you need to deploy all the required libs in your wildfly before running your application. Commented Sep 15, 2017 at 12:42

2 Answers 2

3

I had the same problem and I just fixed it. It is basically a dependency issue. The problem is that you are loading the postgresql and/or postgis jars on your wildfly modules and on you deployments WEB-INF/lib. I connect to my database with a regular DS on my standalone.xml

<datasource jndi-name="java:jboss/datasources/mygisDS" pool-name="mygisDS" use-java-context="true"> <connection-url>jdbc:postgresql://localhost:5432/keycloak</connection-url> <driver>org.postgresql</driver> <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> <pool> <min-pool-size>10</min-pool-size> <max-pool-size>100</max-pool-size> <prefill>true</prefill> <use-strict-min>false</use-strict-min> <flush-strategy>FailingConnectionOnly</flush-strategy> </pool> <security> <user-name>user</user-name> <password>XXXXXX</password> </security> </datasource> 

My drivers

<driver name="org.postgresql" module="org.postgresql"> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> </driver> 

I tried as @Toastor said, it might have solve his issues but it didnt work with me. Although he gave me a few clues.

So most documentation around the internet is outdated, and there is not much on hibernate spatial 5. I added postgis-jdbc to my maven to my postgresql's module.xml inside my wildfly, but as I was reading THIS IS NOT NECESSARY in Hibernate Spatial 5.X. Wildfly 10 uses 5.0.7 by default, I was using hibernate 5.1.0.Final, so I did not set the scope of any hibernate component on my pom.xml as "provided". But everything kept failing too. So I traced my libraries.

mvn dependency:tree 

You have to check for any postgresql libraries that are called or any postgis libraries. What I found out is that Hibernate Spatial 5.1 has some postgresql dependencies, so I excluded them from hibernate spatial.

 <exclusion> <artifactId>postgresql</artifactId> <groupId>org.postgresql</groupId> </exclusion> 

I did this and I found a problem with PGobject, it said something like class not found. So I added it to jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <dependencies> <module name="org.postgresql" /> </dependencies> </deployment> </jboss-deployment-structure> 

And this did the work. If you have a similar problem use maven dependency:tree to trace your libraries.

Sign up to request clarification or add additional context in comments.

Comments

2

After struggling for days, I found this solution:

Don't connect to your database through a datasource defined on your wildfly. Instead, in your persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="org.hibernate.events.jpa" transaction-type="JTA"> <properties> <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/> <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/yourdatabase"/> <property name="hibernate.connection.username" value="username"/> <property name="hibernate.connection.password" value="password"/> <property name="hibernate.connection.pool_size" value="5"/> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.max_fetch_depth" value="5"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> 

Because the early 5.0.x versions of hibernate apparently had no proper integration of hibernate-spatial and to avoid classpath problems, I added the file jboss-deployment-structure.xml to my META-INF:

<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <exclusions> <module name="org.hibernate" /> <module name="org.postgresql" /> </exclusions> </deployment> </jboss-deployment-structure> 

This will prevent the wildfly provided hibernate to be used by your deployment so that you can instead add a dependency for the most recent hibernate version (5.1.0 as of this writing). You will then need to add dependencies for hibernate, hibernate-spatial and postgresql-jdbc.

Also note that hibernate 5 doesn't require the @Type annotation anymore.

I have managed to get my project working with the settings above and one of my entities featuring the following attribute / column:

@Column(columnDefinition = "geometry(Point,4326)") private Point position; 

I hope it helps, good luck!

Edit: Using this approach, you need to add your postgresql jdbc driver as a dependency to your project.

Edit:

I have prepared a working sample project demonstrating the use of wf10/hibernate5/postgis - check it out on github:

https://github.com/Pulvertoastmann/wf10postgis/

3 Comments

And using jta-data-source?
No, no data-source required. But here's a fun bit: If you do create a data-source, the above example would work without providing database credentials in your persistence.xml. The credentials of the wf ds will be used. I don't know why... some odd things are going on apparently. To be honest, I stopped investigating once it worked and turned to other things, so I can't offer you any further explanation...
@Toastor, I just tried your sample project. I can insert geometry values, but can't get them back. I created an issue in your sample project github. Hope you can help me. Here is my original post: stackoverflow.com/questions/46164275/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.