Hibernate Spatial on JBoss AS7

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Hibernate Spatial on JBoss AS7

Sergio Teixeira
Greetings,

I wonder if anyone had any luck setting up Hibernate Spatial on JBoss AS 7.0.1? I'm trying to do so, and so far I can run queries which return SDO_GEOMETRY fields, but when I try to insert or update it just won't work.

If I use annotations @PesistenceContext and @PersistenceUnit to inject Hibernate Session and SessionFactory I have the above results. But if I try a 100% native Hibernate persistence approach
e.g.  Session session = HibernateUtil.getSessionFactory().getCurrentSession();
I can't even pull data from the database with a query.

Any indication is greatly appreciated.

Also the DB is Oracle with spatial extension.

Thanks
Sérgio
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Spatial on JBoss AS7

Sergio Teixeira
Just an update to this point.

I've pulled the HS version 1.1.1-SNAPSHOT source code and started debugging on Eclipse. To summarize I'm using Oracle 10g, and ojdbc6. Also Hibernate 3.6.7.

So now I'm stuck in what seems to be the classic Oracle issue which is the ConnectionFinder interface. I'm changing directly the source class DefaultConnectionFinder (just for test purposes). The problem is that the first connection it gets is org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6; then the code picks up oracle.jdbc.driver.T4CConnection and fails:
Caused by: org.hibernatespatial.helper.FinderException: Tried retrieving OracleConnection from oracle.jdbc.driver.T4CConnection using method _getPC, but received null.

What is blocking me now is that T4CConnection can't be casted to oracle.jdbc.driver.OracleConnection or oracle.jdbc.OracleConnection. And as far as I came up with after some research, a guy from Oracle says "Once you have a oracle.jdbc.driver.T4CConnection, that's the Oracle thin dirver connection, and it should work in any Oracle JDBC extension.". So I'm kind of lost on which is the best strategy to follow from here. I made several attemps but couldn't get to an oracle.jdbc.OracleConnection object.

I see there are 2 different related discussions here already (the latest on Jun 08, 2011) but this particular issue is not extensively explained.

Thanks for any comments somebody might put here.

I'll put here a solution in case I find one.

Cheers,
Sérgio
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Spatial on JBoss AS7

Sergio Teixeira
Ok, I finally got it working (although I will have to proceed with more tests). After a bit more investigation I narrowed my investigation target to the class cast exception which was presumably being caused by having an additional ojdbc6.jar in my project setup. I had previously configured the ojdbc6.jar in JBoss AS 7 in a module dedicated to my data-source which is mandatory.
So the trick is to remove the ojdbc6.jar from the EAR before it's published to JBoss. To tell the Hibernate-spatial Oracle project to reference the existing ojdbc6.jar in the JBoss it was necessary to add the Dependency in the MANIFEST.MF by adding the following 2 lines followed by a return carriage:
Name: hibernate/spatial/oracle
Dependencies: com.oracle

Then I added the following to my pom.xml:

          <build>
            <plugins>
              <plugin>
            <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                  <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                                <manifestEntries>
                                        <Dependencies>com.oracle</Dependencies>
                                </manifestEntries>                   
                  </archive>
                </configuration>
              </plugin>
            </plugins>
          </build>   

I did both for the hibernate-spatial-oracle project and also in the final EAR. Maybe it's redundant and working witht the original HS jars untouched works  as well (instead of HS source code) but I just wanted to leave here the solution/guidelines in case someone needs to go for it, and maybe the new version of HS will have to tackle these issues so maybe it will be of some use to the project.

Kind Regards,
Sérgio