3 Replies Latest reply on Mar 14, 2014 10:15 AM by wdfink

    Problem referencing class in Postgresql jdbc driver

    darylfoster

      I have an app running in JBoss AS. The app uses a Postgresql datasource and EclipseLink to interact with the database. I've added a column to one of the tables of type 'path'. Since Java does not have a corresponding datatype, I've created a Converter to map the PGpath object to a List<Point> object. The problem is that the Converter is throwing the following exception:

      java.lang.ClassCastException: org.postgresql.geometric.PGpath cannot be cast to org.postgresql.geometric.PGpath

      I've posted questions on Postgres and EclipseLink forums, and all of the responses that I've received suggest that this is a ClassLoader issue. One suggestion that I received was to make sure that there is only one copy of the driver jar in the application or the JBoss container, but not in both. Is that true? I've tried, but the server will not start without the postgres jdbc jar deployed to the modules directory. The app will throw an exception if I remove the postgres jdbc jar from the ear file.

       

      Any suggestions?

        • 1. Re: Problem referencing class in Postgresql jdbc driver
          wdfink

          Mostly this ClassCast problems are related to the classloaders.

          If you run different applications, i.e. EAR files, and package the driver to each app you might run into that.

          Because if EAR1 put the class into the List which is hold global and EAR2 read it the org.postgresql.geometric.PGpath is loaded by different CL and Java identify the class by it's full-name and the CL.

           

          If you use former AS versions you might add the driver.jar to the lib directory.

          Since AS7 you need to add it as module and set a dependency to this module.

          1 of 1 people found this helpful
          • 2. Re: Problem referencing class in Postgresql jdbc driver
            darylfoster

            I'm rather new to JBoss and to Java in general, so some of my questions may be very basic.

            As further clarification I have two copies of the driver.jar file. One copy is in a subdirectory of $JBOSS_HOME/modules. The other is in the lib directory of the EAR file that I am deploying. I'm only deploying one EAR file.

             

            I am using JBoss Enterprise Application Platform v 6.1.0. Is it possible for me to remove the driver.jar from the EAR file and set a dependency to the module using this version of JBoss?

            • 3. Re: Problem referencing class in Postgresql jdbc driver
              wdfink

              It looks like that you put/get from the List with different classloaders.

              You should remove the driver from your EAR and set a dependency, see Class Loading in AS7.

              See "Dependencies : Manifest Entries" or use the jboss-structure file to set a dependency to your driver module if needed.