The Binding or Converters are not working, the return type of the field 
declared as "Geometry" is reporting "PGgeometry". What can be causing this 
issue? Or in other words how can i overcome this?
Sorry for this probally dumb question but i spent so much time already in 
this issue.

The generated field doesnt works, and the type cast got wrong:
public final TableField<AreaImovelJuntosRecord, Geometry> GEOM = createField
("geom", org.jooq.impl.DefaultDataType.getDefaultDataType(
"\"public\".\"geometry\""), this, "", new PostGisGeometryConverter2());

Geometry value = obj.getValue(OBJ.GEOM, new PostGisGeometryConverter2());
Returns error: java.lang.ClassCastException: org.postgis.PGgeometry cannot 
be cast to org.postgis.Geometry

But this works:
Geometry value = obj.getValue(OBJ.GEOM, new PostGisGeometryConverter2());

My converter and binding are like this: 
( https://github.com/amc6/jooq_postgis_bug_example )
/**
 * Implemented with the help of 
https://groups.google.com/forum/#!topic/jooq-user/TBQZCPTCvnk
 * and 
https://github.com/dmitry-zhuravlev/jooq-postgis-spatial/blob/master/src/main/kotlin/net/dmitry/jooq/postgis/spatial/binding/PostgisGeometryBinding.kt
 */

public class PostGisGeometryBinding2 implements Binding<Object, Geometry> {

    private final PostGisGeometryConverter2 converter = new 
PostGisGeometryConverter2();

    @Override
    public Converter<Object, Geometry> converter() {
        return converter;
    }

    @Override
    public void sql(BindingSQLContext<Geometry> ctx) throws SQLException {
        ctx.render().visit(DSL.sql("?::geometry"));
    }

    @Override
    public void set(BindingSetStatementContext<Geometry> ctx) throws 
SQLException {
        ctx.statement().setObject(ctx.index(), 
ctx.convert(converter).value());
    }

    @Override
    public void get(BindingGetResultSetContext<Geometry> ctx) throws 
SQLException {
        
ctx.convert(converter).value(ctx.resultSet().getObject(ctx.index()));
    }

    @Override
    public void get(BindingGetStatementContext<Geometry> ctx) throws 
SQLException {
        
ctx.convert(converter).value(ctx.statement().getObject(ctx.index()));
    }

    @Override
    public void set(BindingSetSQLOutputContext<Geometry> ctx) throws 
SQLException {
        throw new SQLFeatureNotSupportedException();
    }

    @Override
    public void get(BindingGetSQLInputContext<Geometry> ctx) throws 
SQLException {
        throw new SQLFeatureNotSupportedException();
    }

    @Override
    public void register(BindingRegisterContext<Geometry> ctx) throws 
SQLException {
        throw new SQLFeatureNotSupportedException();
    }
}
public class PostGisGeometryConverter2 implements Converter<Object, 
Geometry> {

        @Override
        public Geometry from(Object t) {
            if (t instanceof PGgeometry)
                return ((PGgeometry) t).getGeometry();
            
            try {
                return t == null ? null : 
PGgeometry.geomFromString(t.toString());
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Object to(Geometry g) {
            System.out.println("TO");
            if (g == null) {
                return null;
            }
            return new PGgeometry(g);
        }

        @Override
        public Class<Object> fromType() {
            return Object.class;
        }

        @Override
        public Class<Geometry> toType() {
            return Geometry.class;
        }
    }

My library xml looks like:
<customTypes>
        <customType>
            <name>Geometry</name>
            <type>org.postgis.Geometry</type>
            
<binding>org.jooq.postgis.spatial.binding.PostGisGeometryBinding2</binding>
            <types>(.*geometry.*|.*GEOMETRY.*)</types>
        </customType>
    </customTypes>
    <forcedTypes>
        <forcedType>
            <userType>org.postgis.Geometry</userType>
            
<converter>org.jooq.postgis.spatial.binding.PostGisGeometryBinding2</converter>
            <name>Geometry</name>
            <types>(.*geometry.*|.*GEOMETRY.*)</types>
        </forcedType>
    </forcedTypes>


What i am missing here?
Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to