Hi Danilo,

Thanks, but that stack trace doesn't seem to be produced by the example
project you've linked:
https://github.com/amc6/jooq_postgis_bug_example

How can I reproduce the problem most easily? Could you perhaps create an
example project based on this one:
https://github.com/jOOQ/jOOQ-mcve

Thanks,
Lukas

On Tue, Nov 27, 2018 at 4:14 PM Danilo da Silveira Figueira <
danilosfigue...@gmail.com> wrote:

> Hi Lukas,
>
> In fact the stacktrace is in my code, because the binding returns a
> PGgeometry, so when i try to receive it as a Geometry it gives me the
> following error:
> Exception in thread "main" java.lang.ClassCastException:
> org.postgis.PGgeometry cannot be cast to org.postgis.Geometry
> at joindb.JoinDatabases.loadPropriedades(JoinDatabases.java:67)
> at joindb.JoinDb.main(JoinDb.java:21)
>
>
> Thanks,
> Danilo
>
> Em terça-feira, 27 de novembro de 2018 09:09:31 UTC-2, Lukas Eder escreveu:
>>
>> Hello,
>>
>> What's the full stack trace of your exception?
>>
>> Thanks
>> Lukas
>>
>> On Tue, Nov 27, 2018 at 6:52 AM <danilos...@gmail.com> wrote:
>>
>>> 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 jooq-user+...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 jooq-user+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to