Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

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

Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

fgdrf
Hello List,

I'm using hibernate spatial on the server and the java objects are
transferred via http and object (de)serialization.

On the client side I get ClassNotFoundExceptions
(org.hibernatespatial.mgeom.MGeometryFactory)
if Geometry Objects are are read from InputStream.

I guess the Factory is set for every created Geometry object. And that
leads my to the following questions:

* Would it be possible to create Geometries without having the
GeometryFactory set? I don't want to have hibernate-spatial
dependencies at client side.
* Is it possible to configure hibernate-spatial how to serialize
Geometry Objects (with/without GeometryFactory)?

Cheers,
Frank
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

Karel Maesen
Administrator
Hi Frank,

Hibernate Spatial is supposed to serialize JTS Geometries to the native database geometry types. If the Geometries are serialized as java objects in stead, then the class mapping or Hibernate configuration is incorrect.

Could you describe how the mapping is done? Are we talking about HS 4.0-M1?

Regards,

Karel

On 21 Sep 2012, at 10:15, Frank Gasdorf wrote:

> Hello List,
>
> I'm using hibernate spatial on the server and the java objects are
> transferred via http and object (de)serialization.
>
> On the client side I get ClassNotFoundExceptions
> (org.hibernatespatial.mgeom.MGeometryFactory)
> if Geometry Objects are are read from InputStream.
>
> I guess the Factory is set for every created Geometry object. And that
> leads my to the following questions:
>
> * Would it be possible to create Geometries without having the
> GeometryFactory set? I don't want to have hibernate-spatial
> dependencies at client side.
> * Is it possible to configure hibernate-spatial how to serialize
> Geometry Objects (with/without GeometryFactory)?
>
> Cheers,
> Frank
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

fgdrf
I use JPA with Hibernate 3.6.8 with hibernate-spatial 1.1

Mapping for attribute of an Entity:

        @Column(columnDefinition = "Geometry")
        @Type(type = "org.hibernatespatial.GeometryUserType")
        private Geometry geometry;

server-side serialization of Objects with an geometry attribute:

        private byte[] createMessageData(final Object data) throws IOException {
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
                new ObjectOutputStream(bos).writeObject(data);
                return bos.toByteArray();
        }

on the http client the Object are read as follows from an InputStream
created from (apache) HttpResponse:

                                                        final ObjectInputStream ois = new ObjectInputStream(is);
                                                        final int num = ois.readInt();
                                                        for (int i = 0; i < num; i++) {
                                                                try {
                                                                        final Object msg = ois.readObject();

 // ... go ahead and work with the objects
                                                                }
                                                                catch (final ClassNotFoundException e) {
                                                                        MessageToolkit.handleExceptions(brokerId, e);
                                                                }
                                                        }




2012/9/21 Karel Maesen <[hidden email]>:

> Hi Frank,
>
> Hibernate Spatial is supposed to serialize JTS Geometries to the native database geometry types. If the Geometries are serialized as java objects in stead, then the class mapping or Hibernate configuration is incorrect.
>
> Could you describe how the mapping is done? Are we talking about HS 4.0-M1?
>
> Regards,
>
> Karel
>
> On 21 Sep 2012, at 10:15, Frank Gasdorf wrote:
>
>> Hello List,
>>
>> I'm using hibernate spatial on the server and the java objects are
>> transferred via http and object (de)serialization.
>>
>> On the client side I get ClassNotFoundExceptions
>> (org.hibernatespatial.mgeom.MGeometryFactory)
>> if Geometry Objects are are read from InputStream.
>>
>> I guess the Factory is set for every created Geometry object. And that
>> leads my to the following questions:
>>
>> * Would it be possible to create Geometries without having the
>> GeometryFactory set? I don't want to have hibernate-spatial
>> dependencies at client side.
>> * Is it possible to configure hibernate-spatial how to serialize
>> Geometry Objects (with/without GeometryFactory)?
>>
>> Cheers,
>> Frank
>> _______________________________________________
>> hibernatespatial-users mailing list
>> [hidden email]
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

Karel Maesen
Administrator
Sorry Frank, I misunderstood your initial question.

HS won't help you here: there is no configuration option that controls how JTS Geometries are created.

You could use serialization to WKT/WKB (Well-Known Text/Binary) in stead of object serialization. JTS supports these formats - see the javadocs. Perhaps you could create a TransferObject with the Geometries replaced by their WKB representation and then serialize that.

Regards,

Karel


On 21 Sep 2012, at 12:30, Frank Gasdorf wrote:

> I use JPA with Hibernate 3.6.8 with hibernate-spatial 1.1
>
> Mapping for attribute of an Entity:
>
> @Column(columnDefinition = "Geometry")
> @Type(type = "org.hibernatespatial.GeometryUserType")
> private Geometry geometry;
>
> server-side serialization of Objects with an geometry attribute:
>
> private byte[] createMessageData(final Object data) throws IOException {
> final ByteArrayOutputStream bos = new ByteArrayOutputStream();
> new ObjectOutputStream(bos).writeObject(data);
> return bos.toByteArray();
> }
>
> on the http client the Object are read as follows from an InputStream
> created from (apache) HttpResponse:
>
> final ObjectInputStream ois = new ObjectInputStream(is);
> final int num = ois.readInt();
> for (int i = 0; i < num; i++) {
> try {
> final Object msg = ois.readObject();
>
> // ... go ahead and work with the objects
> }
> catch (final ClassNotFoundException e) {
> MessageToolkit.handleExceptions(brokerId, e);
> }
> }
>
>
>
>
> 2012/9/21 Karel Maesen <[hidden email]>:
>> Hi Frank,
>>
>> Hibernate Spatial is supposed to serialize JTS Geometries to the native database geometry types. If the Geometries are serialized as java objects in stead, then the class mapping or Hibernate configuration is incorrect.
>>
>> Could you describe how the mapping is done? Are we talking about HS 4.0-M1?
>>
>> Regards,
>>
>> Karel
>>
>> On 21 Sep 2012, at 10:15, Frank Gasdorf wrote:
>>
>>> Hello List,
>>>
>>> I'm using hibernate spatial on the server and the java objects are
>>> transferred via http and object (de)serialization.
>>>
>>> On the client side I get ClassNotFoundExceptions
>>> (org.hibernatespatial.mgeom.MGeometryFactory)
>>> if Geometry Objects are are read from InputStream.
>>>
>>> I guess the Factory is set for every created Geometry object. And that
>>> leads my to the following questions:
>>>
>>> * Would it be possible to create Geometries without having the
>>> GeometryFactory set? I don't want to have hibernate-spatial
>>> dependencies at client side.
>>> * Is it possible to configure hibernate-spatial how to serialize
>>> Geometry Objects (with/without GeometryFactory)?
>>>
>>> Cheers,
>>> Frank
>>> _______________________________________________
>>> hibernatespatial-users mailing list
>>> [hidden email]
>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>>

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Issues with Serialization of Geometries ClassNotFoundException org.hibernatespatial.mgeom.MGeometryFactory

fgdrf
Thanks Karel, it seems that we used an other serialization
implementation in the past..

Nevertheless, what do you think about having such a (configuration)
modus to support standard serialisazion without having never used
dependencies on the client. What would happens if we clone the
Geometries before serializing it. Are there any uitility classes to
create copies of Geometries without coping the GeometryFactory?

In regrats,
Frank

2012/9/21 Karel Maesen <[hidden email]>:

> Sorry Frank, I misunderstood your initial question.
>
> HS won't help you here: there is no configuration option that controls how JTS Geometries are created.
>
> You could use serialization to WKT/WKB (Well-Known Text/Binary) in stead of object serialization. JTS supports these formats - see the javadocs. Perhaps you could create a TransferObject with the Geometries replaced by their WKB representation and then serialize that.
>
> Regards,
>
> Karel
>
>
> On 21 Sep 2012, at 12:30, Frank Gasdorf wrote:
>
>> I use JPA with Hibernate 3.6.8 with hibernate-spatial 1.1
>>
>> Mapping for attribute of an Entity:
>>
>>       @Column(columnDefinition = "Geometry")
>>       @Type(type = "org.hibernatespatial.GeometryUserType")
>>       private Geometry geometry;
>>
>> server-side serialization of Objects with an geometry attribute:
>>
>>       private byte[] createMessageData(final Object data) throws IOException {
>>               final ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>               new ObjectOutputStream(bos).writeObject(data);
>>               return bos.toByteArray();
>>       }
>>
>> on the http client the Object are read as follows from an InputStream
>> created from (apache) HttpResponse:
>>
>>                                                       final ObjectInputStream ois = new ObjectInputStream(is);
>>                                                       final int num = ois.readInt();
>>                                                       for (int i = 0; i < num; i++) {
>>                                                               try {
>>                                                                       final Object msg = ois.readObject();
>>
>> // ... go ahead and work with the objects
>>                                                               }
>>                                                               catch (final ClassNotFoundException e) {
>>                                                                       MessageToolkit.handleExceptions(brokerId, e);
>>                                                               }
>>                                                       }
>>
>>
>>
>>
>> 2012/9/21 Karel Maesen <[hidden email]>:
>>> Hi Frank,
>>>
>>> Hibernate Spatial is supposed to serialize JTS Geometries to the native database geometry types. If the Geometries are serialized as java objects in stead, then the class mapping or Hibernate configuration is incorrect.
>>>
>>> Could you describe how the mapping is done? Are we talking about HS 4.0-M1?
>>>
>>> Regards,
>>>
>>> Karel
>>>
>>> On 21 Sep 2012, at 10:15, Frank Gasdorf wrote:
>>>
>>>> Hello List,
>>>>
>>>> I'm using hibernate spatial on the server and the java objects are
>>>> transferred via http and object (de)serialization.
>>>>
>>>> On the client side I get ClassNotFoundExceptions
>>>> (org.hibernatespatial.mgeom.MGeometryFactory)
>>>> if Geometry Objects are are read from InputStream.
>>>>
>>>> I guess the Factory is set for every created Geometry object. And that
>>>> leads my to the following questions:
>>>>
>>>> * Would it be possible to create Geometries without having the
>>>> GeometryFactory set? I don't want to have hibernate-spatial
>>>> dependencies at client side.
>>>> * Is it possible to configure hibernate-spatial how to serialize
>>>> Geometry Objects (with/without GeometryFactory)?
>>>>
>>>> Cheers,
>>>> Frank
>>>> _______________________________________________
>>>> hibernatespatial-users mailing list
>>>> [hidden email]
>>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>>>
>
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users