Hibernate Spatial with OSGi problem(postgis)

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

Hibernate Spatial with OSGi problem(postgis)

rosklyar
This post has NOT been accepted by the mailing list yet.
Hello!

I'm trying to use Hibernate Spatial in my OSGI bundle, but during creating session factory I got an exception:
Exception in thread "pool-1-thread-1" java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
        at org.hibernate.type.TypeResolver.heuristicType(TypeResolver.java:128)
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:297)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:290)
        at org.hibernate.mapping.Property.isValid(Property.java:217)
        at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:463)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:1332)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835)
        at com.aurumsoft.admp.webui.DBBroker.connect(DBBroker.java:69)
        at com.aurumsoft.admp.webui.DBBroker.openSession(DBBroker.java:79)
        at com.aurumsoft.admp.webui.SessionContext$1.run(SessionContext.java:76)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:547)
        at java.util.ArrayList.get(ArrayList.java:322)
        at org.hibernatespatial.HBSpatialExtension.forceConfigure(HBSpatialExtension.java:159)
        at org.hibernatespatial.HBSpatialExtension.configure(HBSpatialExtension.java:151)
        at org.hibernatespatial.HBSpatialExtension.getDefaultSpatialDialect(HBSpatialExtension.java:200)
        at org.hibernatespatial.GeometryUserType.configure(GeometryUserType.java:65)
        at org.hibernatespatial.GeometryUserType.initialize(GeometryUserType.java:82)
        at org.hibernatespatial.GeometryUserType.sqlTypes(GeometryUserType.java:233)
        at org.hibernate.type.CustomType.<init>(CustomType.java:70)
        at org.hibernate.type.CustomType.<init>(CustomType.java:64)
        at org.hibernatespatial.GeometryUserType.<clinit>(GeometryUserType.java:61)
        ... 17 more
Can anyone help me? Where I was wrong?
I added to the classpath of the bundle the next jars:
hibernate-commons-annotations-3.2.0.Final.jar,
hibernate-core-3.6.0.Final.jar,
hibernate-jpa-2.0-api-1.0.0.Final.jar,
javassist-3.11.0.GA.jar,
postgis-jdbc-1.3.3.jar,
postgis-stubs-1.3.3.jar,
postgresql-8.4-701.jdbc3.jar,
dom4j-1.6.1.jar,
hibernate-spatial-1.1.1.jar,
hibernate-spatial-postgis-1.1.1.jar,
jts-1.12.jar

Note that it worked excellent when I used spatial in standalone application, but problems occured when I
made my application as OSGI bundle.
Many thanks for any help!

Best regards,
Rostislav.
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Spatial with OSGi problem(postgis)

rosklyar
This post has NOT been accepted by the mailing list yet.
Looking through the source code I found the reason:
//HBSpatialExtension.java
ClassLoader loader = Thread.currentThread().getContextClassLoader();
        Enumeration<URL> resources = null;
        try {
            resources = loader.getResources("META-INF/services/"
                    + SpatialDialectProvider.class.getName());
            Set<String> names = new HashSet<String>();
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                InputStream is = url.openStream();
                try {
                    names.addAll(providerNamesFromReader(is));
                } finally {
                    is.close();
                }
            }
There is no needed jar in ContextClassLoader when we are using OSGI.
I don't understand why, but it's true. How can we fix it?

Best regards,
Rostislav.