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.
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.
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:
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.