Обсуждение: "package org.postgresql.util does not exist" compilation problem

Поиск
Список
Период
Сортировка

"package org.postgresql.util does not exist" compilation problem

От
Santiago Álvarez Martínez
Дата:

Hi:

I'm developing a Java application, using Maven, Spring and Hibernate, and Postgre (with Postgis) as DBMS.

Everything went OK, until I had to import the org.postgresql.util package, to use the PGobject class, in a UserType Hibernate class.

I got the following errors:

[...]
[loading org/postgis/Geometry.class(org/postgis:Geometry.class)]
[loading org/postgis/binary/BinaryParser.class(org/postgis/binary:BinaryParser.class)]
[loading org/postgis/binary/BinaryWriter.class(org/postgis/binary:BinaryWriter.class)]
/home/perseo/PFC/maven.1264475335794/src/main/java/es/udc/fiestas/model/util/types/PointType.java:15: package org.postgresql.util does not exist
import org.postgresql.util.PGobject;
                          ^

[...]
[checking es.udc.fiestas.web.pages.usuario.CambiarUbicacion]
[checking es.udc.fiestas.model.util.types.PointType]
/home/perseo/PFC/maven.1264475335794/src/main/java/es/udc/fiestas/model/util/types/PointType.java:56: cannot find symbol
symbol  : class PGobject
location: class es.udc.fiestas.model.util.types.PointType
        PGobject pgo = (PGobject) rs.getObject(names[0]);
        ^

/home/perseo/PFC/maven.1264475335794/src/main/java/es/udc/fiestas/model/util/types/PointType.java:[56,24] cannot find symbol
symbol  : class PGobject
location: class es.udc.fiestas.model.util.types.PointType

In my pom.xml file, I've included the dependencies for both Postgre and Postgis, and Eclipse doesn't complain about them (neither in the pom.xml file, nor in the PointType.java):

        <!-- PostgreSQL -->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>8.4-701.jdbc4</version>
        </dependency>

        <!-- PostGIS -->
        <dependency>
            <groupId>org.postgis</groupId>
            <artifactId>postgis-jdbc</artifactId>
            <version>1.3.3</version>
        </dependency>

Is there any issue with Postgre JDBC that doesn't allow to use their classes like any other package?

Note: I have to import that class, to be used here:
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
            throws HibernateException, SQLException {
        PGobject pgo = (PGobject) rs.getObject(names[0]);
        BinaryParser bp = new BinaryParser();
        return (Point) bp.parse(pgo.getValue());
    }
As the returned object is a PGobject (from a Geometry Postgis column), I use the PGobject getValue() method to access its content, so I can't generalize that.

Thank you in advance.

Nice regards.

Santiago.

Re: "package org.postgresql.util does not exist" compilation problem

От
Craig Ringer
Дата:
On 03/08/10 23:18, Santiago Álvarez Martínez wrote:
>
> Hi:
>
> I'm developing a Java application, using Maven, Spring and Hibernate,
> and Postgre (with Postgis) as DBMS.
>
> Everything went OK, until I had to import the org.postgresql.util
> package, to use the PGobject class, in a UserType Hibernate class.
>
> I got the following errors:
>
> [...]
> [loading org/postgis/Geometry.class(org/postgis:Geometry.class)]
> [loading
> org/postgis/binary/BinaryParser.class(org/postgis/binary:BinaryParser.class)]
> [loading
> org/postgis/binary/BinaryWriter.class(org/postgis/binary:BinaryWriter.class)]
> /home/perseo/PFC/maven.1264475335794/src/main/java/es/udc/fiestas/model/util/types/PointType.java:15:
> package org.postgresql.util does not exist


I can import and use org.postgresql.util.PGobject in a Maven project
with the same version of PgJDBC. See example project:

  http://www.postnewspapers.com.au/~craig/pgdemo.zip

Is it possible there's an elderly version of the PostgreSQL JDBC driver
on the classpath that lacks the org.postgresql.util package?

--
Craig Ringer

Tech-related writing: http://soapyfrogs.blogspot.com/

Re: "package org.postgresql.util does not exist" compilation problem

От
Santiago Álvarez Martínez
Дата:

Hi, Craig:

Thanks for your reply.

I've just discovered where the error was (and, as I supposed, it was my fault).

Before adding the PostgreSQL dependency, I had this one, some lines before:

        <dependency>
            <groupId>${jdbcDriver.groupId}</groupId>
            <artifactId>${jdbcDriver.artifactId}</artifactId>
            <version>${jdbcDriver.version}</version>
            <scope>test</scope>
        </dependency>

And that scope parameter, made Maven ignore the dependency until the test phase...

Once removed, everything works fine.

Thank you very much.

Santiago.